當前一個我做的,從MsDatabase和字符串後選擇數據後沒有按下刪除按鈕時,來自一個或多個參數給定值
query = "delete from RegisterItem where Name =" +txtName1.Text+"";
它顯示了一個錯誤說沒有從一個或多個給定值參數,雖然我已經檢查txtName1匹配名稱
{
OleDbConnection connect = new OleDbConnection();
public MenClothing(string text)
{
InitializeComponent();
txtUsername.Text = text;
connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Teronkee\Desktop\OFFICAL STAC\StacProductions\DatabaseSaveItem.accdb";
}
public MenClothing()
{
InitializeComponent();
connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Teronkee\Desktop\OFFICAL STAC\StacProductions\DatabaseSaveItem.accdb";
}
private int upperCase(string pass)
{
int num = 0;
foreach (char ch in pass)
{
if (char.IsUpper(ch))
{
num++;
}
}
return num;
}
private void btnlogout_Click(object sender, EventArgs e)
{
this.Hide();
Form2 Return = new Form2(txtUsername.Text);
Return.ShowDialog();
}
private void MenClothing_Load(object sender, EventArgs e)
{
try
{
connect.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connect;
string query = "select * from RegisterItem";
command.CommandText = query;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
comboBox1.Items.Add(reader["Name"].ToString());
}
connect.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
}
connect.Close();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox1.ImageLocation = ItemUrl.Text;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
pictureBox1.ImageLocation = ItemUrl.Text;
}
private void button1_Click(object sender, EventArgs e)
{
try {
connect.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connect;
command.CommandText = "insert into RegisterItem([Name], [Url],[Description], [Price]) values('" + ItemName.Text + "','" + ItemUrl.Text + "','" + ItemDescription.Text + "','" + ItemPrice.Text + "')";
string str = ItemUrl.Text;
pictureBox1.ImageLocation = str;
string str1 = textBox1.Text;
Image img = Image.FromFile(str);
pictureBox1.Image = img;
command.ExecuteNonQuery();
MessageBox.Show("Data Saved");
txtID1.Text = txtUsername.Text;
txtName1.Text = ItemName.Text;
txtDescription1.Text = ItemDescription.Text;
txtPrice1.Text = ItemPrice.Text;
ItemName.Text = "";
ItemDescription.Text = "";
ItemPrice.Text = "";
connect.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error " +ex);
}
connect.Close();
}
private void label5_Click(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
private void btnDelete_Click(object sender, EventArgs e)
{
try
{
connect.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connect;
string query = "delete from RegisterItem where Name =" +txtName1.Text+"";
command.CommandText = query;
command.ExecuteNonQuery();
MessageBox.Show("Data deleted ");
connect.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
}
connect.Close();
//if (txtUsername.Text == txtID1.Text)
// {
// txtName1.Text = "";
// txtDescription1.Text = "";
// txtPrice1.Text = "";
// }
}
private void ItemDescription_TextChanged(object sender, EventArgs e)
{
}
private void AddString_Click(object sender, EventArgs e)
{
string namestr = txtName1.Text;
comboBox1.Items.Add(namestr);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
connect.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connect;
string query = "select * from RegisterItem where Name='" + comboBox1.Text + "'";
command.CommandText = query;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
txtName1.Text = reader["Name"].ToString();
txtDescription1.Text = reader["Description"].ToString();
txtPrice1.Text = reader["Price"].ToString();
}
connect.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
}
connect.Close();
}
}
}
它的工作原理,當我走進ID交換的名稱(第二行)(第一行) ,但沒有與我想要的名稱 – TeaCake