-
August 20th, 2015, 10:08 PM
#1
exec what is that for within a sqlstament using with executenonequery?
Hello,
to create a table for an mssql server, using ADO.net, I can make it with or without exec:
Code:
string sqlstament = "CREATE TABLE [dbo]. newTable" +
" ([RID][int] NOT NULL PRIMARY KEY CLUSTERED, [Contact][nvarchar](3) NULL," +
"[Company][nvarchar](40) NULL) ON [PRIMARY]";
mySQlCommand.Commandtext = sqlstament;
mySQlCommand.ExecuteNonQuery;
or with 'exec',
Code:
string sqlstament = "EXEC ('CREATE TABLE [dbo]. newTable" +
" ([RID][int] NOT NULL PRIMARY KEY CLUSTERED, [Contact][nvarchar](3) NULL," +
"[Company][nvarchar](40) NULL) ON [PRIMARY]')";
mySQlCommand.Commandtext = sqlstament;
mySQlCommand.ExecuteNonQuery();
both works fine.
But I have no idea what I win if I use exec?
-
September 13th, 2015, 05:52 PM
#2
Re: exec what is that for within a sqlstament using with executenonequery?
Exec ist a keyword to construct the sql-statement with parameters, like here:
"EXEC ('CREATE TABLE ' + @myTable + '( Yourfields')";
In that case you the sqlcommand needs to have :
myCmd.Parameters.AddWithValue("@myTable", SqlDbType.Text).Value = strtblName;
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|