以下是我写的代码,所以请检查并告诉我有什么问题。 我在这里发布了插入和更新代码。
我从youtube上学到了这一点,所以我不知道有关数据库的每一个细节,所以请用一个像我这样的业余爱好者的语言发帖
public void bsave_Click(object sender, RoutedEventArgs e)
{
SQLiteConnection sqliyeCon = new SQLiteConnection(dbConnectionString);
//open connection to database
try
{
sqliyeCon.Open();
string Query = "insert into employeeinfo (name,surname,age) values('" + this.name.Text + "', '" + this.surname.Text + "' , '" + this.age.Text + "')";
SQLiteCommand createCommand = new SQLiteCommand(Query, sqliyeCon);
createCommand.ExecuteNonQuery();
MessageBox.Show("Data is saved succesfully");
sqliyeCon.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void bup_Click(object sender, RoutedEventArgs e)
{
SQLiteConnection sqliyeCon = new SQLiteConnection(dbConnectionString);
//open connection to database
try
{
sqliyeCon.Open();
string Query = "update employeeinfo set eid='" + this.eid.Text + "' , name ='" + this.name.Text + "',surname='" + this.surname.Text + "', age='" + this.age.Text + "' where eid=eid='" + this.eid.Text + "' ";
SQLiteCommand createCommand = new SQLiteCommand(Query, sqliyeCon);
createCommand.ExecuteNonQuery();
MessageBox.Show("Updated");
sqliyeCon.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
答案 0 :(得分:1)
"' where eid=eid='"
应为"' where eid='"
string Query = "update employeeinfo set eid='" + this.eid.Text + "' , name ='" + this.name.Text + "',surname='" + this.surname.Text + "', age='" + this.age.Text + "' where eid='" + this.eid.Text + "' ";