保存超时,为什么数据却保存成功?
WEBSERVICE 一个插入数据函数
[WebMethod]
public string InsertData(DataTable dt)
{
SqlConnection conn2 = GetConn();
SqlTransaction t = conn2.BeginTransaction();
SqlCommand Cmd = conn2.CreateCommand();
Cmd.Transaction = t;
try
{
foreach (DataRow dr in dt.Rows)
{
Cmd.Parameters.Clear();
Cmd.CommandText = "insert into productdata(orderdate,ordernumber,address,customer,phone,specification,receivable,remark,station,depot,arristationdate) Values(@orderdate,@ordernumber,@address,@customer,@phone,@specification,@receivable,@remark,@station,@depot,@arristationdate)";
Cmd.Parameters.Add(new SqlParameter("@orderdate", dr["orderdate"].ToString()));
Cmd.Parameters.Add(new SqlParameter("@ordernumber", dr["ordernumber"].ToString()));
Cmd.Parameters.Add(new SqlParameter("@address", dr["address"].ToString()));
Cmd.Parameters.Add(new SqlParameter("@customer", dr["customer"].ToString()));
Cmd.Parameters.Add(new SqlParameter("@phone", dr["phone"].ToString()));
Cmd.Parameters.Add(new SqlParameter("@specification", dr["specification"].ToString()));
Cmd.Parameters.Add(new SqlParameter("@receivable", dr["receivable"].ToString()));
Cmd.Parameters.Add(new SqlParameter("@remark", dr["remark"].ToString()));
Cmd.Parameters.Add(new SqlParameter("@station", dr["station"].ToString()));
Cmd.Parameters.Add(new SqlParameter("@depot", dr["depot"].ToString()));
Cmd.Parameters.Add(new SqlParameter("@arristationdate", dr["arristationdate"].ToString()));
int intResult=Cmd.ExecuteNonQuery();
}
t.Commit();
}
catch (Exception ext)
{
t.Rollback();
return (ext.Message);
}
finally
{
Cmd.Clone();
conn2.Close();
}
return ("true");
}
客户端调用插入数据:
private void buttonSave_Click(object sender, EventArgs e)
{
dataGridView1.EndEdit();
bscustomers.EndEdit();
DataTable result = (DataTable)bscustomers.DataSource;
DataTable tableAdded = result.GetChanges(DataRowState.Added);
if (tableAdded != null && tableAdded.Rows.Count > 0)
{
string strvalue = s.InsertData(tableAdded);
if (strvalue == "true")
{
MessageBox.Show("保存成功");
((DataTable)(bscustomers.DataSource)).AcceptChanges();
}
else
{
MessageBox.Show(strvalue);
}
}
}
上面是使用C#调用WEBSERVICE插入数据,如果数