c#,使用 visual studio 2012,能够保存到数据库但不能更新
c#, using visual studio 2012 ,able to save to database but cannot update
下面是我写的代码,请大家检查一下,说说哪里不对。
我在此处 post 编辑了插入和更新代码。
我是从 youtube 上学到的,所以我不知道关于数据库的每一个细节,所以请post用像我这样的业余爱好者能理解的语言
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);
}
}
}
"' 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 + "' ";
下面是我写的代码,请大家检查一下,说说哪里不对。 我在此处 post 编辑了插入和更新代码。
我是从 youtube 上学到的,所以我不知道关于数据库的每一个细节,所以请post用像我这样的业余爱好者能理解的语言
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);
}
}
}
"' 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 + "' ";