Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# CommandBuilder alternative or way to use CommandBuilder without a connection?

Tags:

c#

sql

sql-server

I need to (at runtime) build some SQL statements to update a database that I am NOT connected to. Right now I am using a String.Format to build the query, but it's difficult to deal with all the different parameter cases (different datatypes, null, values, escaping, etc..).

What I'd like is to use CommandBuilder--but CommandBuilder requires a DataAdapter which requires a connection and I'm not connected to my database (this is a stand alone utility).

Is there a way to use CommandBuilder in a disconnected state or how can I build this well formatted SQL query in a way that will require me to write a minimal amount of code?

(Target DB is SQL Server)

like image 600
scotru Avatar asked Jul 01 '26 17:07

scotru


1 Answers

Is there a way to use CommandBuilder in a disconnected state?

Unfortunately NO.

SqlCommandBuilder is designed to work with a SqlDataAdapter and a SqlCommand object, or just a SqlCommand, and from the documenttation it needs to connect to the database to retrieve information shema.

like image 61
Chris Avatar answered Jul 04 '26 08:07

Chris