A.Momtahan

I can only set a static query in DataSet designer

How do i send and set query to DataTableAdapter by the code



Re: .NET Framework Data Access and Storage How should I send query to datatableadapter?

Babak Izadi

Hi there,

You want to use this in Win. App or Web App. !

_______________________________________________
May the God blessings be.

LotraSoft Ltd.






Re: .NET Framework Data Access and Storage How should I send query to datatableadapter?

A.Momtahan

Hi

I want to use this in Win App.





Re: .NET Framework Data Access and Storage How should I send query to datatableadapter?

Sivavenkat17

Momtahan,

Please try the below coding fragment and let me know. You can include the 'WHERE' clauses with concatenation of values or go ahead for parameters.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Filling dataset with query during runtime...

string connectionString = "PROVIDER=SQLOLEDB;SERVER=C6433;DATABASE=CRM;UID=sa;PWD=sa";
OleDbConnection conn = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand("SELECT * FROM MY_TABLE",conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,
"MY_TABLE");
dataGridView1.DataSource = ds;
dataGridView1.DataMember =
"MY_TABLE";

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Cheers,
Venkat





Re: .NET Framework Data Access and Storage How should I send query to datatableadapter?

A.Momtahan

Thank you.

but i don't want to use DataAdapter . All i say is about DataTableAdapter





Re: .NET Framework Data Access and Storage How should I send query to datatableadapter?

ahmedilyas

I don't think you can do this, one of the limitations when using the DataSet/TableAdapter wizard. You will have to create either other TableAdapters with a different query or programmatically as shown, use the standard approach (not using the wizard) of using the "raw" DataAdapter.






Re: .NET Framework Data Access and Storage How should I send query to datatableadapter?

Paul P Clement IV


I haven't tried this before but I believe you need to override the Commands using a partial class:

http://blogs.msdn.com/vbteam/archive/2005/05/04/ExtendingTableAdapters.aspx






Re: .NET Framework Data Access and Storage How should I send query to datatableadapter?

JThiloR

Double click in the dataset designer on your TableAdapter.

Now use a partial class like the following:

namespace MyTest.TestDatasetTableAdapters

{

public partial class QueriesTableAdapter : System.ComponentModel.Component

{

// TODO: insert your query instead of this code

public void StartTransactionalChangeBiofeedback(SqlConnection con,

System.Nullable<System.Guid> PK_BiofeedbackInput, System.Nullable<System.DateTime> EndDateTime)

{

SqlCommand sqlComm1 = ((System.Data.SqlClient.SqlCommand)(this.CommandCollection[ 6] ));

sqlComm1.Connection = con;

sqlComm1.Parameters[1].Value = PK_BiofeedbackInput;

sqlComm1.Parameters[2].Value = EndDateTime;

sqlComm1.ExecuteNonQuery();

}

 

This code uses an existing query with another connection (by a parameter). But you can insert your query inside your function as well. Have a look at the designer generated code - it is very similar to it.