Showing posts with label mahesh arya. Show all posts
Showing posts with label mahesh arya. Show all posts

Monday, 24 June 2013

Excel file fetch data from sql server in 1 second refresh

1.      
2.       Connect with sql server

3.      

4.       Refresh connection property



5.        Go to developer tool à click on visual stio
Click on this work book code

Private Sub Workbook_Open()

Application.OnTime Now + TimeValue("00:00:01"), "SaveThis"

End Sub






6.       Add new module code id
Sub SaveThis()
Application.DisplayAlerts = False
ThisWorkbook.RefreshAll
Application.DisplayAlerts = True
Application.OnTime Now + TimeValue("00:00:01"), "SaveThis"
End Sub

Run use it

Saturday, 24 December 2011

Repater on windows from

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Billing;Integrated Security=True");
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            fillRepeater();
            fillRepeater2();
        }
        private void fillRepeater()
        {
            string str = "Select distinct Specification from packingList where packingId=8";
            SqlDataAdapter da = new SqlDataAdapter(str,con);
            DataTable dt = new DataTable();
            DataSet1 ds = new DataSet1();
            da.Fill(dt);
         
                Int32 gh = dt.Rows.Count;
         
                label1.DataBindings.Add("Text", dt, "Specification");
                dataRepeater1.DataSource = dt;
               
               
          
        }
        private void fillRepeater2()
        {
           

            string str = "Select * from packingList where packingId=8 and Specification='" + label1.Text+ "'";
            SqlDataAdapter da = new SqlDataAdapter(str, con);
            DataTable dt = new DataTable();
            da.Fill(dt);

            label2.DataBindings.Add("Text", dt, "ListId");
            label3.DataBindings.Add("Text", dt, "SpType");
            label4.DataBindings.Add("Text", dt, "Quantity");
            label5.DataBindings.Add("Text", dt, "Unit");
            label6.DataBindings.Add("Text", dt, "CrossWt");
            textBox1.DataBindings.Add("Text", dt, "NetWt");
             
        }

    }
}