I want to work with SQL scripts in my desktop application. But I can not write any sql statements with parameters and call them.
INSERT INTO table
VALUES (..., ..., ...)
Above should my SQL statement; where I want to fill the values at c# side. How should my S开发者_如何转开发QL statement; what is its notation? And how can I add at c# parameters to it.
Thanks !
You're going to want to use parameterized SQL queries. Here's an example using the SqlParameter class.
If you need to use external sql script files you can use SQLCMD, a command line tool available for SQL Server 2005 or later.
You can just trigger sqlcmd with Process.Start from C# and pass it the necessary parameters. Here's an article explaining how to pass in variables for starters.
If you are just looking for table update/inserts though I'd recommend going with SqlCommand/SqlParameters as wsanville suggested.
精彩评论