Friday 15 June 2012

C# - SQL Server - ? parameters and Oledb -


I am writing a small frame in C # to import data to SQL Server.

I have seen that if you try to use it? The placeholder of the parameter, if you use the System.Data.SqlClient namespace, then they do not work.

However, if you use the System.Data.OleDb namespace to work with the database, then they work fine. (You just have to add provider = SQLOLEDB to your connect string)

So I have some questions, because? Syntax is necessary for my solution:

  1. Is there a choice to use the named parameter with the system SQL Data Client? I want to use the command parameter.
  2. Can a namespace (ADO provider) be used on another?
  3. Is there any other reason that I have a namespace other?

To expand what I am trying to do, my framework will take a class decorated with some custom features and will generate SQL as follows:

  myTable (col1, col2, ...) INSERT values ​​(?,?, ...)  

This string is an IDbCommand and many IDataParameters and each Execution nonclaim can only be set for idata parameter.

Any thoughts?

EDIT: I tried to use the named parameter p0, p1, etc. as a responder is described and it is working very well on SqlClient, however if I use Olead So, errors saying this:

  must be declared "scalar variable @ p0".  

My parameter is created like this:

  New OLDEPPMATOR ("p" + index, gettip); // GetType works to get the right SqlDbType  

What's wrong? I tried to add and remove the @ symbol to get any benefit in the parameter name.

Last Editing: Have I Used Oleb? And use the SqlClient nominal parameter. I can change back and forth for new providers.

The behavior of those classes uses OleDb ?, the SqlClient parameter is named.

Perfomance: I do not have a standard, but I think the SQL client should perform better with a SQL Server compared to OleDB. SQL client is clear for any type of data source (even excel) for SQL Server, ODDI. But pls try by trying it out.

With SqlClient you can also have "Order of Parameter", just call the parameter @ Parama 1, @ Ultimate 2, @ Ultimate 3. ....


No comments:

Post a Comment