能否给点关键代码?
string connstring = "server=localhost;database=maomao;integrated security=SSPI";
SqlConnection myconn = new SqlConnection(connstring );
SqlCommand mycomm = myconn.CreateCommand();
mycomm.CommandText = "INSERT INTO 进货表单 (进货编号,商品名称,进货日期,进货数量,商品单价,进货支出"+
")VALUES(+'"+b+"','"+n+"','"+d+"','"+num+"','"+p+"','"+m+"'"+
")";
myconn.Open();
mycomm.ExecuteNonQuery();
myconn.Close();
store();
}
public void store()
{
string connstring = "server=localhost;database=maomao;integrated security=SSPI";
SqlConnection myconn = new SqlConnection(connstring);
SqlCommand mycomm = myconn.CreateCommand();
mycomm.CommandText = "SELECT 商品名称 FROM 库存表单";
myconn.Open();
SqlDataReader dr = mycomm.ExecuteReader();
while (dr.Read())
{
if (name.Text == dr["商品名称"].ToString())
{
myconn.Close();
cunzai();
}
else
{
myconn.Close();
bucunzai();
}
}
}
public void cunzai()
{
string connstring = "server=localhost;database=maomao;integrated security=SSPI";
SqlConnection myconn = new SqlConnection(connstring);
SqlCommand mycomm = myconn.CreateCommand();
mycomm.CommandText = "UPDATA 库存表单 SET 库存数量+='"+number.Text .Trim()+"'"+
"WHERE 商品名称='"+name.Text.Trim()+"'";
myconn.Open();
mycomm.ExecuteNonQuery();
myconn.Close();
}
public void bucunzai()
{
string connstring = "server=localhost;database=maomao;integrated security=SSPI";
SqlConnection myconn = new SqlConnection(connstring);
SqlCommand mycomm = myconn.CreateCommand();
mycomm.CommandText = "INSERT INTO 库存表单(商品名称,库存数量"+
")VALUES('"+name.Text.Trim()+"','"+number.Text.Trim()+"')";
myconn.Open();
mycomm.ExecuteNonQuery();
myconn.Close();
}
可以么?