Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > What is the data member when using a stored procedure?
 

What is the data member when using a stored procedure?

Hello -

I am trying to display the results of a parameterized stored stored procedure in a form. The datasource is supposed to be the dataset, correct? What is the datamember supposed to represent?

Any help will be greatly appreciated
Shannon10  Tuesday, March 31, 2009 10:15 PM

Hi,

The procedure is the same as executing the command text in a manner.

The following is an example calling the Procedure:


conn = new SqlConnection(ConnectionString);

SqlCommand comm = new SqlCommand();

comm.Connection = conn;

comm.CommandType = CommandType.StoredProcedure;

comm.CommandText = "proaa"; // the name of procedure in the SQL Server

SqlParameter[] par = new SqlParameter[1];

par[0] = new SqlParameter("@ID",SqlDbType.Int);

par[0].Direction = ParameterDirection.Input;

par[0].Value = 1;

comm.Parameters.AddRange(par);

adapter = new SqlDataAdapter(comm);

dataset = new DataSet();

adapter.Fill(dataset,"dt01");

dataGridView1.DataSource = dataset;

dataGridView1.DataMember = "dt01";

The following link is for your reference:

HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET

If I misunderstood you, or you have other questions, please feel free to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Thursday, April 02, 2009 8:22 AM

Hi,

The procedure is the same as executing the command text in a manner.

The following is an example calling the Procedure:


conn = new SqlConnection(ConnectionString);

SqlCommand comm = new SqlCommand();

comm.Connection = conn;

comm.CommandType = CommandType.StoredProcedure;

comm.CommandText = "proaa"; // the name of procedure in the SQL Server

SqlParameter[] par = new SqlParameter[1];

par[0] = new SqlParameter("@ID",SqlDbType.Int);

par[0].Direction = ParameterDirection.Input;

par[0].Value = 1;

comm.Parameters.AddRange(par);

adapter = new SqlDataAdapter(comm);

dataset = new DataSet();

adapter.Fill(dataset,"dt01");

dataGridView1.DataSource = dataset;

dataGridView1.DataMember = "dt01";

The following link is for your reference:

HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET

If I misunderstood you, or you have other questions, please feel free to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Thursday, April 02, 2009 8:22 AM

Hi Shannon,

Ling has given an excellent example of how to assign the DataSource. Simply said, we cannot directly assign DataSet as DataSource. Instead we could assign the DataTable which resides inside the DataSet. If we want to set the DisplayMember and ValueMember, we could get the Column Names from that DataTable inside the DataSet. This is the common architecture regardless of any kind of data access in DotNet.


-- Chandramohan.P

Chandramohan Palaniswamy  Monday, May 11, 2009 10:55 AM

You can use google to search for other answers

Custom Search

More Threads

• Unhandled Exception
• Open source version?
• Auto-Updating DataBindings
• Simpler example of SmartClient web service file retrieval than AppraisalWorkbench?
• Looking to build a Terrarium like world
• Problems with Server
• Have trouble introducing my own bug
• Proxy problems
• Task Vision V2.0 (VB.Net) change language problem!
• Installation Failure