[英]To create registration form using C# and SQLite
I would like to create a simple registration form for WINDOWS application. 我想为WINDOWS应用程序创建一个简单的注册表格。 I am using SQLite database which can be embedded into the project as I need to create a .exe file and mail it to my friend.
我正在使用可以嵌入到项目中的SQLite数据库,因为我需要创建一个.exe文件并将其邮寄给我的朋友。
Now my registration form has 2 text boxes. 现在我的注册表有2个文本框。
textBox1 for name 名称的textBox1
textBox2 for password 密码的textBox2
I need to insert these 2 values into the table and I have written the following code. 我需要将这两个值插入表中,并且编写了以下代码。
using Finisar.SQLite; 使用Finisar.SQLite;
namespace Task_Sa 命名空间Task_Sa
public partial class Form2 : Form
{
string connectionString;
public Form2()
{
InitializeComponent();
connectionString = @"Data Source=database.db;Version=3;New=True;Compress=True;";
}
private void button1_Click(object sender, EventArgs e)
{
using (SQLiteConnection sqlite_conn = new SQLiteConnection(connectionString))
{
SQLiteCommand cmd = new SQLiteCommand();
cmd.CommandText = @"INSERT INTO TaskTable(UserName,PassWord) values(@userName,@passWord)";
cmd.Connection = sqlite_conn;
cmd.Parameters.Add(new SQLiteParameter("@userName",textBox1.Text)); -> ERROR
}
}
}
}
here I am getting the error as the parameters are not matching. 由于参数不匹配,在这里出现错误。 2 parameters should be of type string and dbType.
2个参数的类型应为string和dbType。 Please help me to complete the code in this regard.
请帮助我完成这方面的代码。 I have copied and pasted SQLite dll file in debug folder of my project and I also have used the " using Finisar.SQLite; " name space.
我已将SQLite dll文件复制并粘贴到项目的调试文件夹中,并且还使用了“ using Finisar.SQLite; ”命名空间。
尝试这个
cmd.CommandText = "INSERT INTO TaskTable(UserName,PassWord) values('"+ textBox1.Text +"','"+ textBox2.Text +"')";
Add a blank space before TaskTable
and values
: 在
TaskTable
和values
之前添加一个空格:
Your version: 您的版本:
cmd.CommandText = @"INSERT INTO TaskTable(UserName,PassWord) values(@userName,@passWord)";
Modified version: 修改版本:
cmd.CommandText = @"INSERT INTO TaskTable (UserName,PassWord) values (@userName,@passWord)";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.