【发布时间】:2018-01-28 18:51:04
【问题描述】:
我正在使用基于服务的数据库在 c# 中完成我的简单任务。我有一个基于服务的数据库,其中有表 staff,其中包含 id、name 和 password 列。我正在尝试使用 C# 代码将新记录插入到该表中,但它没有插入,只是告诉我“没有添加记录”,即使没有错误。
我的代码是:
private void button5_Click(object sender, EventArgs e)
{
try
{
connetionString = Properties.Settings.Default.testdbConnectionString;
cnn = new SqlConnection(connetionString);
cnn.Open();
SqlCommand command6;
string sql6 = null;
sql6 = "insert into staff (name,pwd,id) values(@n,@p,@fid)";
command6 = new SqlCommand(sql6, cnn);
command6.Parameters.AddWithValue("@n", "jhon");
command6.Parameters.AddWithValue("@p", "test");
command6.Parameters.AddWithValue("@fid", 1);
int result = command6.ExecuteNonQuery();
if (result == 0)
{
MessageBox.Show("Record ADDED");
}
else
{
MessageBox.Show("No Record ADDED");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
如果您需要更多详细信息,请更正我的错误。谢谢
【问题讨论】:
-
Sock puppet account。或许您可以阅读How to Ask 并通过tour 了解如何提出好问题并节省创建多个帐户的时间
-
@Plutonix 我的问题有什么问题吗?任何不完整的细节?