updatedatabse through ado.net

Discussion in 'C#' started by manojkumarmaithil, Jun 24, 2007.

  1. manojkumarmaithil

    manojkumarmaithil New Member

    Joined:
    Jun 18, 2007
    Messages:
    14
    Likes Received:
    1
    Trophy Points:
    0
    hello plesehelp me to sort out this problem
    when i use the update command it doesn't work
    coding is here tis is in c#
    Code:
    sqlconnection  con=new sqlconnection();
    con.connectionstring="data source=server; initial catalog=db;user id=sa";
    con.open();
    sqlcommand cmd=new sqlcommand("select * from table1",con);
    dataset sd=new dataset("table1");
    sqldataadapter da=new sqldataadapter(cmd);
    da.fill(ds,"table1");
    datagrid dg=new datagrid();
    dg.datasource=ds;
    dg.datamember="table1";
    da.update(ds,"table1");
    con.close();
    
    while i use this coding it shows exception ;
    but when i take datagrid through wizard and establishe connection then update command is worked;. please some body help me . :)
     
    Last edited by a moderator: Jun 24, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You have posted the thread in the Introduce yourself forum, Please be careful to have the thread in the right forum. I have moved the thread to C# forum for you.

    Also learn to use the code blocks for the code you put in the posts.
     
  3. new292

    new292 New Member

    Joined:
    Jul 11, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Developer
    Location:
    Egypt
    try this

    Code:
    sqlconnection  con=new sqlconnection();
    con.connectionstring="data source=server; initial catalog=db;user id=sa";
    con.open();
    sqlcommand cmd=new sqlcommand("select * from table1",con);
    dataset sd=new dataset("table1");
    sqldataadapter da=new sqldataadapter(cmd);
    da.fill(sd,"tbl_store");
    da.fillSchema(sd,schematype.source,"tbl_store");
    datagrid dg=new datagrid();
    dg.datasource=ds.Tables["tbl_store"];
    da.update(ds,"table1");
    con.close();
    
    
    it will work

    dataset name recommended not to be same as table name
    to update you must get the schema from data adapter
     
  4. new292

    new292 New Member

    Joined:
    Jul 11, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Developer
    Location:
    Egypt
    ooooooooooooops
    there is amistake

    Code:
    sqlconnection  con=new sqlconnection();
    con.connectionstring="data source=server; initial catalog=db;user id=sa";
    con.open();
    sqlcommand cmd=new sqlcommand("select * from table1",con);
    dataset sd=new dataset("table1");
    sqldataadapter da=new sqldataadapter(cmd);
    da.fill(sd,"tbl_store");
    da.fillSchema(sd,schematype.source,"tbl_store");
    datagrid dg=new datagrid();
    dg.datasource=ds.Tables["tbl_store"];
    da.update(ds,"tbl_store");
    con.close();
    
    
    it will work

    dataset name recommended not to be same as table name
    to update you must get the schema from data adapter
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice