当我在“寄存器(文本框)”上输入文本时,它会显示错误,因为该表的类型是“数字”,所以我需要像“它必须给我编号”这样的错误处理消息......
我需要像“* 是必填字段,您必须向它们插入数据”这样的必填字段消息
其实我不知道如何使用我刚刚尝试过的“异常”......
private void button1_Click(object sender, EventArgs e)
{
conn = new OracleConnection(oradb);
conn.Open();
cmd = new OracleCommand();
cmd.Connection = conn;
try
{
string sql = "INSERT INTO SCHOOL (STUDENTNAME, REGISTER,) VALUES (:STUDENTNAME, :REGISTER)";
cmd = new OracleCommand(sql, conn);
cmd.Parameters.Add(new OracleParameter(":STUDENTNAME", textBox1.Text));
cmd.Parameters.Add(new OracleParameter(":REGISTER", textBox2.Text));
cmd.ExecuteNonQuery();
MessageBox.Show("Done");
conn.Close();
}
catch (Exception ex) //that ex shows me error
{
MessageBox.Show("Not inserted!");
}
finally
{
conn.dispose(); //close connection
}