C# 使用sql数据库c的登录表单#
我正在做一个注册页面。您将用户名和密码及其保存保存在sql数据库中 注意:在我添加第二列(密码)之前,evrey thing一直工作 这是密码(用户名相同): 这是按钮设置:C# 使用sql数据库c的登录表单#,c#,sql,winforms,login,sql-server-ce,C#,Sql,Winforms,Login,Sql Server Ce,我正在做一个注册页面。您将用户名和密码及其保存保存在sql数据库中 注意:在我添加第二列(密码)之前,evrey thing一直工作 这是密码(用户名相同): 这是按钮设置: private void button1_Click(object sender, EventArgs e) { if (deleteBox.Text != "") { SQLFunctions
private void button1_Click(object sender, EventArgs e)
{
if (deleteBox.Text != "")
{
SQLFunctions.Insert(insertBox.Text);
SQLFunctions.delete(deleteBox.Text);
SQLFunctions.Refresh(this.dataGridView1);
}
else
{
MessageBox.Show("login failed");
}
}
谢谢我想您需要像这样修改代码
SqlCeCommand commandInsert = new SqlCeCommand("INSERT INTO [Table] VALUES(@username,@Password)", connection);
SqlCeCommand commandInsert = new SqlCeCommand("INSERT INTO [Table](password) VALUES(@Password)", connection);
command.Parameters.AddWithValue("@Password", insertBox.Text);
您应该传递两个参数,因为您现在在db中有两个字段,如果您不想传递username,那么您应该这样指定
SqlCeCommand commandInsert = new SqlCeCommand("INSERT INTO [Table] VALUES(@username,@Password)", connection);
SqlCeCommand commandInsert = new SqlCeCommand("INSERT INTO [Table](password) VALUES(@Password)", connection);
command.Parameters.AddWithValue("@Password", insertBox.Text);
而且
commandInsert.Parameters.Add("Password", _Password);
这应该写如下
commandInsert.Parameters.Add("@Password", _Password);
要将值传递给这个参数,可以这样做
SqlCeCommand commandInsert = new SqlCeCommand("INSERT INTO [Table] VALUES(@username,@Password)", connection);
SqlCeCommand commandInsert = new SqlCeCommand("INSERT INTO [Table](password) VALUES(@Password)", connection);
command.Parameters.AddWithValue("@Password", insertBox.Text);
错误是什么?另外,当您说u
Insert
时,您的表是否只有Password
作为一列?为我们提供表结构。为什么在插入时函数名为delete?您将用户名插入一行,将密码插入另一行。它们之间没有任何联系。你应该调查一下。此外,除了其他人所说的之外,你不应该让方法如此明显地误导:如果用户名的代码是相同的,这肯定不会起作用,因为你有“INSERT INTO[Table]value(@Password)”,但字段的顺序可能会导致将密码插入用户名字段。您应该在SQL查询中指定要插入的字段。