C# SQL语句点击按钮生成一张新数据库表,表名在textbox1中,输入ABC后,提示'ABC' 附近有语法错误。
privatevoidbutton1_Click(objectsender,EventArgse){stringsqlstr="createtable'"+textBox...
private void button1_Click(object sender, EventArgs e)
{
string sqlstr = "create table'"+textBox1 .Text +"'(ID int identity(1,1) primary key,data varchar(20))";
SqlConnection sqldata = new SqlConnection("server=localhost;database=DataBase;integrated security=SSPI");
sqldata.Open();
SqlCommand cmd2 = new SqlCommand(sqlstr, sqldata );
cmd2.ExecuteNonQuery();
sqldata.Close();
} 展开
{
string sqlstr = "create table'"+textBox1 .Text +"'(ID int identity(1,1) primary key,data varchar(20))";
SqlConnection sqldata = new SqlConnection("server=localhost;database=DataBase;integrated security=SSPI");
sqldata.Open();
SqlCommand cmd2 = new SqlCommand(sqlstr, sqldata );
cmd2.ExecuteNonQuery();
sqldata.Close();
} 展开
展开全部
将 string sqlstr = "create table'"+textBox1 .Text +"'(ID int identity(1,1) primary key,data varchar(20))"; 改成 :
string sqlstr = "create table "+textBox1 .Text +" (ID int identity(1,1) primary key,data varchar(20))";
string sqlstr = "create table "+textBox1 .Text +" (ID int identity(1,1) primary key,data varchar(20))";
更多追问追答
追问
我试过了,不行,提示'tableABC'附近有语法错误
追答
示'table ABC'附近有语法错误 和 ABC之间 要有空格啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询