本文介绍了查询在sql中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在sql数据库中插入数据,例如插入表名(name)values(''mahesh'')中,其中id = 102;如何在c#.net
I want to insert data in sql data base eg.insert into tablename(name) values(''mahesh'') where id=102; how to fire such query in c# .net
推荐答案
#region Hàm thêm Product vào chi tiết order
public static void InsertCTOrder(int OrderID, int ProID, int Quantity, string UnitPrice,int ktra,SqlConnection sqlconn)
{
string strInSert = "INSERT INTO OderDetail VALUES (@OrderID, @ProID, @Quantity, @UnitPrice)";
SqlCommand sqlcmd = new SqlCommand(strInSert, sqlconn);
sqlcmd.Parameters.AddWithValue("@OrderID", OrderID);
sqlcmd.Parameters.AddWithValue("@ProID", ProID);
sqlcmd.Parameters.AddWithValue("@Quantity", Quantity);
sqlcmd.Parameters.AddWithValue("@UnitPrice", UnitPrice);
try
{
sqlconn.Open();
sqlcmd.ExecuteNonQuery();
sqlconn.Close();
ktra = 0;
}
catch (Exception )
{
sqlconn.Close();
ktra = 1;
}
}
这篇关于查询在sql中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!