0

当我在“寄存器(文本框)”上输入文本时,它会显示错误,因为该表的类型是“数字”,所以我需要像“它必须给我编号”这样的错误处理消息......

我需要像“* 是必填字段,您必须向它们插入数据”这样的必填字段消息

其实我不知道如何使用我刚刚尝试过的“异常”......

 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
            }
4

2 回答 2

0

改变你的

string sql = "INSERT INTO SCHOOL (STUDENTNAME, REGISTER,) VALUES (:STUDENTNAME, :REGISTER)";
                                                      ^^^

string sql = "INSERT INTO SCHOOL (STUDENTNAME, REGISTER) VALUES (:STUDENTNAME, :REGISTER)";

你的REGISTER专栏后面多了一个逗号。

于 2013-10-21T07:31:06.760 回答
0

注册后去掉逗号

string sql = "INSERT INTO SCHOOL (STUDENTNAME, REGISTER Check this , ) VALUES (:STUDENTNAME, :REGISTER)

于 2013-10-21T07:29:02.083 回答