本文介绍了请帮我插入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(@"Data Source=ASUS\SQLEXPRESS;Initial Catalog=E1;Integrated Security=True;");
                con.Open();
               // string str = "CREATE TABLE'"+textBox1.Text+"(userid number(10),password varchar2(20),email varchar2(20));'";
                string str = "CREATE TABLE " + textBox1.Text + " (dataid varchar(10), data varchar());";
                SqlCommand cmd = new SqlCommand(str, con);
                cmd.ExecuteNonQuery();
                string str1 = "insert into users(userid,password,email) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox4.Text + "')";
                SqlCommand cmd1 = new SqlCommand(str1, con);
                cmd1.ExecuteNonQuery();
                MessageBox.Show("Table created");
            }
            catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
}





我的尝试:



i我试图运行它,但是当我运行它时,它会在'('



What I have tried:

i am trying to run this but when i run it,it says incorrect syntax near '('

推荐答案

"CREATE TABLE " + textBox1.Text + " (dataid varchar(10), data varchar(10));";



这篇关于请帮我插入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 03:07