Visual C#中INSERT INTO语句的问题# [英] Problems with INSERT INTO statement in Visual C#

查看:106
本文介绍了Visual C#中INSERT INTO语句的问题#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的"INSERT"会导致语法错误?我尝试运行以下代码时的语句:


private void btn_save_Click(object sender,EventArgs e)

        {

           试试
            {

                connection.Open();

                OleDbCommand command = new OleDbCommand();

                command.Connection = connection;

                //command.CommandText ="插入学生(姓名,年龄,Gpa)值('" + txt_name.Text +"','" + txt_age.Text +"','" + txt_gpa。文字+"')" ;;

                command.CommandText =" INSERT INTO学生(姓名,年龄,Gpa)价值('Abeni',20,3.2)" ;;

                command.ExecuteNonQuery();

                MessageBox.Show(" Data Saved");

            }¥b $ b            catch(异常处理)

            {

                MessageBox.Show(" Error" + excpt);

            }¥b $ b        }



解决方案

你得到的确切语法错误是什么?

Why am I am getting syntax errors resulting from my "INSERT" statement when I try to run the following code:

private void btn_save_Click(object sender, EventArgs e)
        {
            try
            {
                connection.Open();
                OleDbCommand command = new OleDbCommand();
                command.Connection = connection;
                //command.CommandText = "insert into students(Names, Age, Gpa) values('" + txt_name.Text +"','" + txt_age.Text + "','" + txt_gpa.Text + "')";
                command.CommandText = "INSERT INTO students (Names, Age, Gpa) VALUES ('Abeni', 20, 3.2)";
                command.ExecuteNonQuery();
                MessageBox.Show("Data Saved");
            }
            catch(Exception excpt)
            {
                MessageBox.Show("Error" + excpt);
            }
        }


解决方案

What is the exact syntax error you are getting?


这篇关于Visual C#中INSERT INTO语句的问题#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆