当我试图通过我创建的软件将一些数据保存到我的 sql (表达式) 时, 我有一个错误 。
An unhandled exception of type System.InvalidOperationException occurred in System.Data.dll. Additional information: ExecuteNonQuery: Connection property has not been initialized.
这是我的密码:
private void save_medicine_Click(object sender, EventArgs e)
{
cn.Open();
if (nameBox.Text != "" & companyBox.Text != "" & categoryBox.Text != "" &
amountBox.Text != "" & restockBox.Text != "" & buyBox.Text != "" &
sellBox.Text != "" & qualityComboBox.Text !="" )
{
cmd.CommandText = "insert into drug_info (name,company_id,category,
expiration_date,stock_level,
critical_level_drug,cost_buy,cost_sell,drug_quality)
values ( "+nameBox.Text+" , "+companyBox.Text+" , "+
categoryBox.Text+" , "+dateTimePicker1+" , "+amountBox+" , "
+restockBox+" , "+buyBox+" , "+sellBox+" , "
+qualityComboBox+" )";
cmd.ExecuteNonQuery();
cmd.Clone();
}
}
}