I create a SqlDataAdapter
after a fill it to Dataset
. My question is that after insert I want to get the IDENTITY
value for primary column. For example a give buttonedit1 editvalue is Id
(this is my primary column) after insert I want to get Identity value in ButtonEdit1 text.
Can I make this unless use SQL command like Select @IDentity
thanks.
public void Form1_Load(object sender,EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(@"ConString");
con.Open();
adap = new SqlDataAdapter("select Id,Caption from SKMenu where ID=-1",con);
adap.Fill(ds, "Table");
bs.DataSource = ds.Tables["Table"];
buttonEdit1.DataBindings.Add("Text", bs, "Id");
buttonEdit2.DataBindings.Add("Text", bs, "Caption");
bs.AddNew();
}
private void button1_Click(object sender, EventArgs e)
{
SqlCommandBuilder cv = new SqlCommandBuilder(adap);
bs.EndEdit();
adap.Update(ds.Tables["Table"]);
}