请更正我的创建表查询 [英] Please correct my create table query

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

问题描述

 

  private   void  button1_Click( object  sender,EventArgs e)
{
尝试
{
SqlConnection con = new SqlConnection( @ 数据源= ABHINAV-PC\SQLEXPRESS;初始目录= E1;集成安全性=真;);
con.Open();
string str = CREATE TABLE' + textBox1.Text + (用户ID号码(10),密码varchar2(20),电子邮件varchar2(20) ));';
SqlCommand cmd = new SqlCommand(str,con);
cmd.ExecuteNonQuery();
MessageBox.Show( 表创建);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}





我的尝试:



i不知道我在这个创建表查询中做错了什么...文本框字段将决定表名

解决方案

< blockquote> TableName 之间缺少空格。其次查询格式不正确(单引号):

 SqlConnection con =  new  SqlConnection( @ 数据源= ABHINAV-PC\SQLEXPRESS;初始目录= E1;集成安全性=真;); 
con.Open();
string str = CREATE TABLE + textBox1.Text + (用户ID号码(10),密码varchar2(20),电子邮件varchar2(20) ));;

SqlCommand cmd = new SqlCommand(str,con);
cmd.ExecuteNonQuery();


private void button1_Click(object sender, EventArgs e)
       {
           try
           {
               SqlConnection con = new SqlConnection(@"Data Source=ABHINAV-PC\SQLEXPRESS;Initial Catalog=E1;Integrated Security=True;");
               con.Open();
               string str = "CREATE TABLE'"+textBox1.Text+"(userid number(10),password varchar2(20),email varchar2(20));'";
               SqlCommand cmd = new SqlCommand(str, con);
               cmd.ExecuteNonQuery();
               MessageBox.Show("Table created");
           }
           catch (Exception ex)
               {
                   MessageBox.Show(ex.Message);
               }
       }



What I have tried:

i dont know what i'm doing wrong in this create table query...the textbox field will decide the table name

解决方案

There is a space missing between Table and TableName. Secondly query is not properly formatted(single quote):

SqlConnection con = new SqlConnection(@"Data Source=ABHINAV-PC\SQLEXPRESS;Initial Catalog=E1;Integrated Security=True;");
con.Open();
string str = "CREATE TABLE "+ textBox1.Text +" (userid number(10), password varchar2(20), email varchar2(20));";

SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();


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

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