protected void Button1_Click1(object sender, EventArgs e)
{
string year = tb_year.Text;
string gross = tb_gross.Text;
string rating = DropDownList2.SelectedValue;
string director = tb_director.Text;string sel = DropDownList1.SelectedValue;
string query = "UPDATE MovieList SET ReleaseYear=@YearValue," +
"Gross=@GrossValue, Rating=@RatingValue," +
"Director=@DirectorValue WHERE Rank=@SelValue";
System.Data.OleDb.OleDbCommand ocmd =
new System.Data.OleDb.OleDbCommand(query,
new System.Data.OleDb.OleDbConnection(CSTR));
ocmd.Parameters.AddWithValue("@YearValue", year);
ocmd.Parameters.AddWithValue("@GrossValue", gross);
ocmd.Parameters.AddWithValue("@RatingValue", rating);
ocmd.Parameters.AddWithValue("@DirectorValue", director);
ocmd.Parameters.AddWithValue("@SelValue", sel);
ocmd.Connection.Open();
ocmd.ExecuteNonQuery();
ocmd.Connection.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
string year = tb_year.Text;
string gross = tb_gross.Text;
string rating = DropDownList2.SelectedValue;
string director = tb_director.Text;
string sel = DropDownList1.SelectedValue;
string query = "DELETE FROM MovieList WHERE Movie=" + DropDownList1.SelectedItem.Text + "'";
System.Data.OleDb.OleDbCommand ocmd =
new System.Data.OleDb.OleDbCommand(query,
new System.Data.OleDb.OleDbConnection(CSTR));
ocmd.Parameters.AddWithValue("@YearValue", year);
ocmd.Parameters.AddWithValue("@GrossValue", gross);
ocmd.Parameters.AddWithValue("@RatingValue", rating);
ocmd.Parameters.AddWithValue("@DirectorValue", director);
ocmd.Parameters.AddWithValue("@SelValue", sel);
ocmd.Connection.Open();
ocmd.ExecuteNonQuery(); <<***
ocmd.Connection.Close();
populateDropDowns();
}
}
}
按钮1是更新按钮,当我更改值时,它可以更新数据库信息,此按钮可以立即更新信息。
但删除按钮,当我删除信息时,它会抛出一条错误信息:
&#34; OleDbException未被用户代码处理:附加信息: 查询表达式中的语法错误(缺少运算符)&#39; Movie = The Matrix 转&#39;&#39 ;.在&#34; ***&#34;。
但是,当我再次打开此网站时,信息将被删除。如何解决此错误信息并立即删除信息?
答案 0 :(得分:1)
以与更新相同的方式执行此操作,对where子句使用SQL参数。所以这段代码应该有效:
protected void Button2_Click(object sender, EventArgs e)
{
string sel = DropDownList1.SelectedValue;
// if your selection is empty, abort early
if( sel == null || string.IsNullOrEmpty(sel.Text)) return;
// use a SQL parameter like you did with update
string query = "DELETE FROM MovieList WHERE Movie=@MovieValue";
System.Data.OleDb.OleDbCommand ocmd =
new System.Data.OleDb.OleDbCommand(query,
new System.Data.OleDb.OleDbConnection(CSTR));
// here the selected text for the movie is set to the movie parameter
ocmd.Parameters.AddWithValue("@MovieValue", sel.Text);
ocmd.Connection.Open();
ocmd.ExecuteNonQuery();
ocmd.Connection.Close();
populateDropDowns();
}
答案 1 :(得分:-2)
byte[] encrypt = null;
byte [] decrypt = aesCipher2.doFinal(encrypt);
您应该使用上述内容更改查询,但缺少java.lang.IllegalArgumentException: Null input buffer