Results 1 to 2 of 2

Thread: About Datagrid

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Location
    Dhaka, Bangladesh
    Posts
    102

    About Datagrid

    How can I insert some rows from a datagrid to a database ?

    Rajib

  2. #2
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Re: About Datagrid

    not be the best one, but hope this would help
    VB Code:
    1. private void Form1_Load(object sender, System.EventArgs e)
    2.         {
    3.             //conn is a connection from sql
    4.             //DataAdapter da
    5.             //ds is your DataSet
    6.             da.SelectCommand=new SqlCommand("select * from student",conn);
    7.             ds.Tables.Add(new DataTable("test"));
    8.             da.Fill(ds.Tables["test"]);
    9.             this.dataGrid1.DataSource=ds.Tables["test"];
    10.            
    11.         }
    12.  
    13.         private void btnsave_click(object sender, System.EventArgs e)
    14.         {
    15.             if (ds.HasChanges())
    16.             {
    17.                 SqlCommandBuilder cm = new SqlCommandBuilder(da);
    18.                 da.Update(ds,"test");
    19.             }
    20.                
    21.         }
    cheers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width