为什么这段代码不起作用 [英] Why this code isnt working
本文介绍了为什么这段代码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码来创建一个表,如果它不存在:
I've this code to create a table if it doesnt exists:
MessageBox.Show("create table");
conn.Open();
SqlCommand command = new SqlCommand("IF OBJECT_ID('UXMenu', 'U') IS NULL CREATE TABLE UXMenu(ID int PRIMARY KEY AUTOINCREMENT, TransDocument char(5), TransSerial char(5), TransDocNumber float, PartyName char(60), PartyLocalityID char(5), TotalAmount char (25), ShipToPostalCode char(35), Estado int);", conn); command.ExecuteNonQuery();
MessageBox.Show("tabela criada");
conn.close();
但此代码不工作,我得到第一个消息框,但它只是忽略了其余的代码,并没有创建任何东西。
我尝试过:
But this code isnt working, I get the first messagebox but then it just ignores the rest of the code and doesnt create anything.
What I have tried:
MessageBox.Show("create table");
conn.Open();
SqlCommand command = new SqlCommand("IF OBJECT_ID('UXMenu', 'U') IS NULL CREATE TABLE UXMenu(ID int PRIMARY KEY AUTOINCREMENT, TransDocument char(5), TransSerial char(5), TransDocNumber float, PartyName char(60), PartyLocalityID char(5), TotalAmount char (25), ShipToPostalCode char(35), Estado int);", conn);
command.ExecuteNonQuery();
MessageBox.Show("tabela criada");
conn.close();
推荐答案
SqlCommand命令= new SqlCommand(IF OBJECT_ID('UXMenu','U')IS NULL CREATE TABLE UXMenu(ID int PRIMARY KEY IDENTITY(1,1),TransDocument char(5),TransSerial char(5),TransDocNumber float,PartyName char (60),PartyLocalityID char(5),TotalAmount char(25),ShipToPostalCode char(35),Estado int);,conn);
SqlCommand command = new SqlCommand("IF OBJECT_ID('UXMenu', 'U') IS NULL CREATE TABLE UXMenu(ID int PRIMARY KEY IDENTITY(1,1), TransDocument char(5), TransSerial char(5), TransDocNumber float, PartyName char(60), PartyLocalityID char(5), TotalAmount char (25), ShipToPostalCode char(35), Estado int);", conn);
这篇关于为什么这段代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文