开发者

Binding Source get Identity

Given the code below, if there is no row in my sqltable then textbox1.Text is 0; what I would like to do is to update the table from button_click so that my new Id value is generated and retrieved automatically - this is necessary for relational tables.

How can I make this work?

Form_Load
{
    SqlConnection con=new SqlConnection(connectionstring);
    SqlDataAdapter adap=new SqlDataAdapter(selectcommand);
    DataSet rec=new Dataset();
    adap.Fill(Rec);
    BindingSource bs=new BindingSource(rec,"TableName");

    TextBox1.DataBindings.Add("Text",bs,"Id");//Id is my primarykey
    TextBox2.DataBindings.Add("Text",bs,"Name");

    bs.AddNew();
}


button_click
{
    SqlCommandBuilder cb=new SqlCommandBuilder(adap);
    adap.update(rec.Tab开发者_高级运维les["TableName"]);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜