即时通讯从一个webform更新我的数据库的问题。我使用了一系列由数据源填充的文本框和下拉列表,但出于某种原因,我无法更新它们。使用asp.net更新sql server数据库c#
基本上,行的主键传递到下一个页面,其中文本框,下拉列表中填充了该行的数据。
这里是我到目前为止已经试过
//Update the record with new information entered into controls
protected void UpdateBut_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection("Data Source=stephenp\\sqlexpress;Initial Catalog=Asset management System DB;Integrated Security=True"))
{
string sql = "UPDATE Peripherals SET [email protected], [email protected], [email protected], " +
"Company = @Company, [email protected], [email protected], [email protected], [email protected], " +
"[email protected], LastModifiedDate = @LastMD, [email protected] WHERE (PeripheralTagNumber = @PeripheralTagNumber)";
//try
//{
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddWithValue("@PeripheralType", TypeDDL.Text.Trim());
cmd.Parameters.AddWithValue("@Model", ModelTB.Text.Trim());
cmd.Parameters.AddWithValue("@SerialNum", SerialNumTB.Text.Trim());
cmd.Parameters.AddWithValue("@Company", CompanyDDL.Text.Trim());
cmd.Parameters.AddWithValue("@Department", DepartmentDDL.Text.Trim());
cmd.Parameters.AddWithValue("@Status", StatusDDL.Text.Trim());
cmd.Parameters.AddWithValue("@Warranty", DateTime.Parse(WarrantyTB.Text.Trim()).ToShortDateString());
cmd.Parameters.AddWithValue("@CapexNum", CapexNumTB.Text.Trim());
cmd.Parameters.AddWithValue("@IPAddress", IPAddressTB.Text.Trim());
cmd.Parameters.AddWithValue("@LastMD", DateTime.Now.Date.ToShortDateString());
cmd.Parameters.AddWithValue("@LastMB", Session["username"].ToString());
cmd.Parameters.AddWithValue("@PeripheralTagNumber", ID);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
//}
//catch (SqlException ex) { }
}
this.getData();
}
感谢
你得到错误? –
你的爱是什么? –
那么,你的代码问题是什么?例外?错误讯息?不要更新任何内容?请更具体的 – Steve