I would like to put into a list the new ID-Machine (is not automatic), the name of the new machine and select the area (Bereich) where this type of machine belongs to. I try to change to string the ID-number (like in databease access) the ID to get the name of the area in the INSERT INTO query. But I dont know why VS shows that I didnt open the connection (ExecuteNonQuery requires an open and available Connection. The connection's current state is closed)... If anyone can help me, it will be great.
public void bttnSpeichern_Click_1(System.Object sender, EventArgs e)
{
Module.con.Open();
int geraetid = (int)(Conversion.Val(lblGeraetid.Text));
int bereichid = (int)(Conversion.Val(lblBereichID.Text));
if (lblGeraetid.Text == "MaschineID" || lblGeraetid.Text == null || txtGeraetName.Text == null || lblGeraetid.Text == "BereichID" || lblBereichID.Text == null)
{
Interaction.MsgBox("Bitte füllen Sie die Faldern aus", Constants.vbInformation, "Hinweis");
}
else
{
string b = System.Convert.ToString(Interaction.MsgBox("Möchten Sie die Eingaben bestätigen?", (int)Constants.vbQuestion + Constants.vbYesNo, "Anlegen"));
if ( b == Constants.vbYes.ToString())
{
Module.con.Open();
OleDbCommand geraete_anlegen = new OleDbCommand("INSERT INTO tblMaschine(MaschineID,Maschine,BereichID) VALUES (\'"+
lblGeraetid.Text + "\',\'"+
txtGeraetName.Text + "\',\'" +
lblBereichID.Text + "\',\'", Module.con);
geraete_anlegen.ExecuteNonQuery();
Interaction.MsgBox("Gerät wurde erfolgreich angelegt!", Constants.vbInformation, "Neues Gerät");
//clear_text();
Module.con.Close();
display_geraete();
}
}
}