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?
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;