Connecting method
// sb sql
string setting = System.Configuration.ConfigurationManager.AppSettings["ConnectString"].ToString();
SqlConnection myconn = new SqlConnection(setting);
myconn.Open();
SqlCommand cmd = new SqlCommand(sb.ToString(), myconn);
cmd.ExecuteReader();
----------------------------------------
采用存储过程
SqlCommand com = new SqlCommand("PR_Indepot", DBHelper.Connectionstrings);
com.CommandType = CommandType.StoredProcedure;
SqlParameter[] pa ={
new SqlParameter("@id",SqlDbType.Int),
new SqlParameter("@goodsName",SqlDbType.VarChar,50),
new SqlParameter("@type",SqlDbType.VarChar,50),
new SqlParameter("@model",SqlDbType.VarChar,50),
new SqlParameter("@spec",SqlDbType.VarChar,50),
new SqlParameter("@card",SqlDbType.VarChar,50),
new SqlParameter("@price",SqlDbType.Money),
new SqlParameter("@unit",SqlDbType.VarChar,50),
new SqlParameter("@amount",SqlDbType.Int),
new SqlParameter("@pay",SqlDbType.Money),
new SqlParameter("@bid",SqlDbType.Int),
new SqlParameter("@address",SqlDbType.VarChar,50),
new SqlParameter("@linkMan",SqlDbType.VarChar,50),
new SqlParameter("@phone",SqlDbType.VarChar,50)
};
pa[0].Value = ind.Id;
pa[1].Value = ind.GoodsName;
pa[2].Value = ind.GoodsType;
pa[3].Value = ind.Model;
pa[4].Value = ind.Spec;
pa[5].Value = ind.Card;
pa[6].Value = ind.UnitPrice;
pa[7].Value = ind.Unit;
pa[8].Value = ind.Amount;
pa[9].Value = ind.Pay;
pa[10].Value = ind.Bid.Id;
pa[11].Value = ind.Address;
pa[12].Value = ind.LinkMan;
pa[13].Value = ind.Phone;
foreach (SqlParameter p in pa)
{
com.Parameters.Add(p);
}