Saturday, 22 March 2014

To fetch last id from table and to show one incremented value in textbox

SqlCommand cmdtxt = new SqlCommand();
        cmdtxt = new SqlCommand("SELECT pur_id FROM pur_productdb ORDER BY pur_productid DESC", con);
        SqlDataReader reader11 = cmdtxt.ExecuteReader();
        reader11.Read();
        txtpurid.Text = (Convert.ToInt16(reader11["pur_id"]) + 1).ToString();
        reader11.Close();

No comments:

Post a Comment