Sponsored By
MindStick SurveyManager
Advertise with Us
Advertisement
Advertise with Us
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
   

Home >> .Net >> C# >> how achieve batch update data
Author Post

aken H


Total Post: 66
Member Since: 9/6/2011
Points: 419
how achieve batch update data
Posted On: 1/31/2012 11:52:10 AM

hi all,

I am trying to achieve batch update data, but failed to achieve, give correction, the code is as follows
thank in advance.

 public partial class UpdateTranData : Form
    {
        public UpdateTranData()
        {
            InitializeComponent();
        }
        SqlDataAdapter adapter;
        DataSet ds;
        string connectionString = @"data source=StudentDB;initial catalog=MYDB;user=sa;password=PASSWORD;";
        SqlConnection sqlCnn;
        SqlCommand sqlCmd;
        string sql = null;
        private void UpdateTranData_Load(object sender, EventArgs e)
        {
            sql="SELECT *FROM TRAN_INFO";
            sqlCnn = new SqlConnection(connectionString);
            sqlCnn.Open();
            adapter = new SqlDataAdapter(sql, sqlCnn);// specifing SQL statement and Database connection
            ds = new DataSet();//creating instance of DataSet
            adapter.Fill(ds); //filling DataSet
            dataGridView1.DataSource = ds.Tables[0];//Binding DataGridView with DataSet
           
        }
       
      private void btnUpdate_Click(object sender, EventArgs e)
       {
          
           SqlCommandBuilder scb = new SqlCommandBuilder(adapter);
           if (MessageBox.Show("Are you sure?","Warning",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)==DialogResult.Yes)
           {
               try
               {
                   adapter.Update(ds.Tables[0]);
                   sqlCnn.Close();
                   MessageBox.Show("Data updated successful!");
                  
               }
               catch (Exception)
               {

                   MessageBox.Show("Data updated defeat!");
                   sqlCnn.Close();
               }
           }
          private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
           txtID.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
           txtStart_Station.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
           txtEnd_Station.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
           txID.Enabled = false;

        }
   }

Author Post

James Smith


Total Post: 48
Member Since: 3/16/2011
Points: 270
Re: how achieve batch update data
Posted On: 2/1/2012 1:04:06 AM
Hi Aken,
I checked your code. It's working fine. Could you tell me exception or error which you are getting in program so I can understand exact problem.

Thanks.
Report Abuse Form
Reason:    
 
Total Online Users: 6263
Advertisement
MindStick DataConverter
Advertise with Us
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.