Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute multi lined SQL 1

Status
Not open for further replies.

spangeman

Programmer
Oct 16, 2004
96
EU
Hi there.

Using ADO Dot Net could you show me how to execute multi-lined sql. For example I may have some SQL in a string like this that I want to execute

string SqlToExecute =
"UPDATE MYTABLE
SET COL1 = 'FRED'
WHERE COL2 = '1'
GO"
SqlToExecute = SqlToExecute + Environment.NewLine + "UPDATE MYTABLE
SET COL1 = 'DAVE'
WHERE COL2 = '2'
GO"


Regards
Spangeman
 
Just pass it to your ExecuteNonQuery method for the provider you're using. If MS-SqlServer:
Code:
SqlCommand myCommand = new SqlCommand(SqlToExecute, myConnection);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
Code for other providers will be similar.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top