public object max_id(String tbl_name) { object i; string qry = "Select max(id)+1 from " + tbl_name; i = c.MyExecuteScalar(qry); return(i); }
protected void btnSave_Click(object sender, EventArgs e) { string ds1 = c.MyExecuteScalar("Select BalanceQty From ItemTable where ItemName ='" + DropDownList2.SelectedItem.Text + "' ").ToString(); if (ds1 != "") { lbl_BQty.Text = ds1; } int a; int b; a = Convert.ToInt16(txtQty.Text); b = Convert.ToInt16(lbl_BQty.Text); int d = (a) + (b); Label7.Text = d.ToString(); SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["StockDBConnectionString"].ConnectionString); String UPDATESQL; UPDATESQL = "UPDATE ItemTable SET [BalanceQty]=@BalanceQty WHERE [ItemName]='" + DropDownList2.SelectedItem.Text + "'"; SqlCommand cmd = new SqlCommand(UPDATESQL, conn1); cmd.Parameters.AddWithValue("@BalanceQty", Label7.Text); // int add = 0; try { conn1.Open(); cmd.ExecuteNonQuery(); //Label1.Text = add.ToString() + "Record updated"; Response.Write("<script>alert('Records Updated')</script>"); } catch (Exception err) { //Response.Write(err.StackTrace); } finally { conn1.Close(); } // // }