使用C#和finisar sqlite将输入保存到数据库中 [英] Save the input into database using C# and finisar sqlite
问题描述
我遇到问题,当用户输入输入时,我应该在哪里保存数据?我已经连接了sqlite,但我不确定如何保存输入。请关注如何创建登录页面。我有一个connection.xaml.cs和login.xaml.cs。所以这是我的问题。下面是connection.xaml.cs.If possible,给我一个我可以参考和研究的链接。我是sqlite的初学者。谢谢。
I have a problem , when user enter the input, where should I save the data? I'm already connect the sqlite but I'm not sure how to save the input.Let focus on how to create login page. I have a connection.xaml.cs and login.xaml.cs. So this is my problem. Below is the connection.xaml.cs.If possible, give me a link that i can refer and study. I am beginner in sqlite. Thank You.
SQLiteConnection sqlite_conn;
SQLiteCommand sqlite_cmd;
SQLiteDataReader sqlite_datareader;
// create a new database connection:
sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=True;Compress=True;");
// open the connection:
sqlite_conn.Open();
// create a new SQL command:
sqlite_cmd = sqlite_conn.CreateCommand();
// Let the SQLiteCommand object know our SQL-Query:
sqlite_cmd.CommandText = "CREATE TABLE Login (id integer primary key, username varchar(50),password varchar(50));";
// Now lets execute the SQL ;D
sqlite_cmd.ExecuteNonQuery();
// Lets insert something into our new table:
sqlite_cmd.CommandText = "INSERT INTO Login (id,username,password) VALUES (111043, 'zakira' ,'abc123');";
// And execute this again ;D
sqlite_cmd.ExecuteNonQuery();
sqlite_cmd.CommandText = "SELECT * FROM Login";
// Now the SQLiteCommand object can give us a DataReader-Object:
sqlite_datareader = sqlite_cmd.ExecuteReader();
while (sqlite_datareader.Read())
{
string Myreader = sqlite_datareader.GetString(0);
string Myreader2 = sqlite_datareader.GetString(1);
string Myreader3 = sqlite_datareader.GetString(2);
MessageBox.Show(Myreader + " " + Myreader2 + " " + Myreader3);
}
// We are ready, now lets cleanup and close our connection:
sqlite_conn.Close();
}
下面是我的Login.cs.xaml(登录页面)。这就是我已经完成的工作
Below is my Login.cs.xaml (login page). This is what i'm already done
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Dalam Login button");
string query = "select from (Login) where password='" + textBox2.Text + "'";
ExecuteQuery(query);
SQLiteDataReader dr = sqlite_cmd.ExecuteReader();
int count = 0;
//string password = "";
while (dr.Read())
{
count++;
}
if (count == 1)
{
MessageBox.Show("Logged In ");
}
else
MessageBox.Show("Wrong Password :(");
}
private void textBox2_TextChanged(object sender, TextChangedEventArgs e)
{
// textBox2.password = '$';
//dynamicTextBox.ShortcutsEnabled = false;
var textBox = sender as TextBox;
}
}
推荐答案
';
// dynamicTextBox.ShortcutsEnabled = false;
var textBox = sender as TextBox;
}
}
'; //dynamicTextBox.ShortcutsEnabled = false; var textBox = sender as TextBox; } }
请参考以下链接:
< a href =http://blog.tigrangasparian.com/2012/02/09/getting-started-with-sqlite-in-c-part-one/> http://blog.tigrangasparian.com/2012/ 02/09 / getting-started-with-sqlite-in-c-part-one / [ ^ ]
please refer below link:
http://blog.tigrangasparian.com/2012/02/09/getting-started-with-sqlite-in-c-part-one/[^]
这篇关于使用C#和finisar sqlite将输入保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!