sql server - Change datatable and tableadapter schema at runtime according to stored procedure. C# -


I have a dataset and table adapters for the table in that dataset. The problem is that to fill TableAdapter DataTable Uses the stored procedure, but the amount of returned column may vary. How can I change the datatylet's schema on runtime to get all the columns from the stored procedure?

In my opinion, leave the idea of ​​using a data adapter, it is completely unnecessary Do this instead to get DataTable:

 using  (SqlConnection con = new SqlConnection ("Conectionstring")) {con.Open (); (Using SqlCommand commnand = new SqlCommand ("StoredProcName", con)) {command.CommandType = CommandType.StoredProcedure; SqlDataReader Reader = command.ExecuteReader (); Datatyal table = new datatelle (); Table.Load (reader); Return table; }}   

It is no longer a matter that you return the call to the call #, all of them will be included in the dataet

edit: & Lt; Configuration & gt; Move the actual connection to your connection to the following section in your Web.config file under the section. You should be able to copy it from your settings file.

And now create your SqlConnection as follows:

  SqlConnection con = new SqlConnection (Connection Connection ["ConnectionString"]. ConnectionString ))   

Note that "ConnectionString" is the name attribute of the connection string in Web.Config.

In the second case, it is not clear.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -