473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

2 DATA GRID Questions

Hi,

I need to display columns in a data grid based on 7 different queries. Now I
have 32 questions:

1. Is it possble to have 1 single data adapter with 7 queries & 1 data set
or do I need to have a separate data adapter & a separate data set for each
select query?
If thats possible then how?

2. I have the following code which allows the user to enter an order number
& click the view button which should show all information for that
order...But the data gris is not showing the infomation, it is showing the
only the column headings... I am using only 1 data grid for all the
queries... Everytime a different view link (related to a different criteria)
is clicked , I change the DataSource , DataKeyField & DataMember for the grid
which points to a separate data set.

Code ::

private void LinkButton1_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(dsAllAO1);
DataGrid1.DataBind();
}
private void lnkByOrder_Click(object sender, System.EventArgs e)
{
sqlSelectCommand2.Parameters["@o"].Value=txtOrder.Text;

// Different data set
sqlDataAdapter2.Fill(dsByOrder1); DataGrid1.DataSource=
dsByOrder1;
DataGrid1.DataMember="INVOICES";
DataGrid1.DataKeyField= "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

private void lnkByName_Click(object sender, System.EventArgs e)
{
sqlSelectCommand2.Parameters["@n"].Value=txtName.Text;

// Different data set
sqlDataAdapter2.Fill(dsByName1); DataGrid1.DataSource=
dsByName1;
DataGrid1.DataMember="INVOICES";
DataGrid1.DataKeyField= "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

Is smthg wrong with this code? Will the data grid not work if I bound it to
a different data set on different link button clicks?

Thanks

--
pmud
Jul 21 '05 #1
5 2466
pmud wrote:
Hi,

I need to display columns in a data grid based on 7 different queries. Now I
have 32 questions:

1. Is it possble to have 1 single data adapter with 7 queries & 1 data set
or do I need to have a separate data adapter & a separate data set for each
select query?
If thats possible then how?
Yes, you can have 1 single adapter with 7 different queries and 1 data
set. It all depends on how your stored procedure is written. If there
are 7 select statements or unions or whatever, you will get back 7
tables in one stored procedure call that you can then populate into a
data set using the data adapter.

2. I have the following code which allows the user to enter an order number
& click the view button which should show all information for that
order...But the data gris is not showing the infomation, it is showing the
only the column headings... I am using only 1 data grid for all the
queries... Everytime a different view link (related to a different criteria)
is clicked , I change the DataSource , DataKeyField & DataMember for the grid
which points to a separate data set.

Code ::

private void LinkButton1_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(dsAllAO1);
DataGrid1.DataBind();
}
private void lnkByOrder_Click(object sender, System.EventArgs e)
{
sqlSelectCommand2.Parameters["@o"].Value=txtOrder.Text;

// Different data set
sqlDataAdapter2.Fill(dsByOrder1); DataGrid1.DataSource=
dsByOrder1;
DataGrid1.DataMember="INVOICES";
DataGrid1.DataKeyField= "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

private void lnkByName_Click(object sender, System.EventArgs e)
{
sqlSelectCommand2.Parameters["@n"].Value=txtName.Text;

// Different data set
sqlDataAdapter2.Fill(dsByName1); DataGrid1.DataSource=
dsByName1;
DataGrid1.DataMember="INVOICES";
DataGrid1.DataKeyField= "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

Is smthg wrong with this code? Will the data grid not work if I bound it to
a different data set on different link button clicks?
Your code above should run fine, but here is something a little leaner
and easier to debug:

<code>
private void BindData(string sqlQuery, string paramName, object paramValue)
{
DataTable queryTable = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, connection);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
if(paramName != null && paramValue != null)
{
sda.SelectCommand.Paramaters.Add(paramName, paramValue);
}
sda.Fill(queryTable);
DataGrid1.DataSource = queryTable;
DataGrid1.DataKeyField = "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}
</code>

Then, elsewhere in your code, all you would have to do to populate your
datagrid is to just call

private void lnkByName_Click(object sender, System.EventArgs e)
{
// sqlSelectCommand2.Parameters["@n"].Value=txtName.Text;
// // Different data set
// sqlDataAdapter2.Fill(dsByName1);
// DataGrid1.DataSource= dsByName1;
// DataGrid1.DataMember="INVOICES";
// DataGrid1.DataKeyField= "ORDER_NO";
// DataGrid1.AutoGenerateColumns=true;
// DataGrid1.DataBind();

//Replace above with:
BindData("<stored proc name>", "@n", txtName.Text);
}

Thanks


hth,
~d
Jul 21 '05 #2
Hi D.W. Warlock

I have never written stored procedures. but just now I did a tutorial on
them. So I should write a stored procedure with 7 select statements . Then I
use this stored procedure with only one data adapter & 1 data set. & when
the user clicks the view button , the data grid will show the result? Is that
right?

"D.W. Warlock" wrote:
pmud wrote:
Hi,

I need to display columns in a data grid based on 7 different queries. Now I
have 32 questions:

1. Is it possble to have 1 single data adapter with 7 queries & 1 data set
or do I need to have a separate data adapter & a separate data set for each
select query?
If thats possible then how?


Yes, you can have 1 single adapter with 7 different queries and 1 data
set. It all depends on how your stored procedure is written. If there
are 7 select statements or unions or whatever, you will get back 7
tables in one stored procedure call that you can then populate into a
data set using the data adapter.

2. I have the following code which allows the user to enter an order number
& click the view button which should show all information for that
order...But the data gris is not showing the infomation, it is showing the
only the column headings... I am using only 1 data grid for all the
queries... Everytime a different view link (related to a different criteria)
is clicked , I change the DataSource , DataKeyField & DataMember for the grid
which points to a separate data set.

Code ::

private void LinkButton1_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(dsAllAO1);
DataGrid1.DataBind();
}
private void lnkByOrder_Click(object sender, System.EventArgs e)
{
sqlSelectCommand2.Parameters["@o"].Value=txtOrder.Text;

// Different data set
sqlDataAdapter2.Fill(dsByOrder1); DataGrid1.DataSource=
dsByOrder1;
DataGrid1.DataMember="INVOICES";
DataGrid1.DataKeyField= "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

private void lnkByName_Click(object sender, System.EventArgs e)
{
sqlSelectCommand2.Parameters["@n"].Value=txtName.Text;

// Different data set
sqlDataAdapter2.Fill(dsByName1); DataGrid1.DataSource=
dsByName1;
DataGrid1.DataMember="INVOICES";
DataGrid1.DataKeyField= "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

Is smthg wrong with this code? Will the data grid not work if I bound it to
a different data set on different link button clicks?


Your code above should run fine, but here is something a little leaner
and easier to debug:

<code>
private void BindData(string sqlQuery, string paramName, object paramValue)
{
DataTable queryTable = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, connection);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
if(paramName != null && paramValue != null)
{
sda.SelectCommand.Paramaters.Add(paramName, paramValue);
}
sda.Fill(queryTable);
DataGrid1.DataSource = queryTable;
DataGrid1.DataKeyField = "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}
</code>

Then, elsewhere in your code, all you would have to do to populate your
datagrid is to just call

private void lnkByName_Click(object sender, System.EventArgs e)
{
// sqlSelectCommand2.Parameters["@n"].Value=txtName.Text;
// // Different data set
// sqlDataAdapter2.Fill(dsByName1);
// DataGrid1.DataSource= dsByName1;
// DataGrid1.DataMember="INVOICES";
// DataGrid1.DataKeyField= "ORDER_NO";
// DataGrid1.AutoGenerateColumns=true;
// DataGrid1.DataBind();

//Replace above with:
BindData("<stored proc name>", "@n", txtName.Text);
}

Thanks


hth,
~d

Jul 21 '05 #3
Hi D.W. Warlock,

I created a stored procedure which works fine when i run it from the server
explorer.

Stored Procedure Code::
CREATE PROCEDURE dbo.usp_Order (@OrderNo int) AS
select * from IRUS_INVOICES where ORDER_NO = @OrderNo
GO

& then I used the followng code...
private void BindData(string sqlQuery, string paramName, object paramValue)
{
DataTable queryTable = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, sqlConnection1);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
if(paramName != null && paramValue != null)
{
//sda.SelectCommand.Paramaters.Add(paramName, paramValue);
sda.SelectCommand.Parameters.Add(paramName, paramValue);
}
sda.Fill(queryTable);
DataGrid1.DataSource = queryTable;
DataGrid1.DataKeyField = "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

private void lnkByOrder_Click(object sender, System.EventArgs e)
{
BindData("dbo.usp_Order", "@OrderNo",
int.Parse(txtOrder.Text));

}

But when I click the view link , the data grid doesnt show up the records
.... What is wrong with the code?

"D.W. Warlock" wrote:
pmud wrote:
Hi,

I need to display columns in a data grid based on 7 different queries. Now I
have 32 questions:

1. Is it possble to have 1 single data adapter with 7 queries & 1 data set
or do I need to have a separate data adapter & a separate data set for each
select query?
If thats possible then how?


Yes, you can have 1 single adapter with 7 different queries and 1 data
set. It all depends on how your stored procedure is written. If there
are 7 select statements or unions or whatever, you will get back 7
tables in one stored procedure call that you can then populate into a
data set using the data adapter.

2. I have the following code which allows the user to enter an order number
& click the view button which should show all information for that
order...But the data gris is not showing the infomation, it is showing the
only the column headings... I am using only 1 data grid for all the
queries... Everytime a different view link (related to a different criteria)
is clicked , I change the DataSource , DataKeyField & DataMember for the grid
which points to a separate data set.

Code ::

private void LinkButton1_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(dsAllAO1);
DataGrid1.DataBind();
}
private void lnkByOrder_Click(object sender, System.EventArgs e)
{
sqlSelectCommand2.Parameters["@o"].Value=txtOrder.Text;

// Different data set
sqlDataAdapter2.Fill(dsByOrder1); DataGrid1.DataSource=
dsByOrder1;
DataGrid1.DataMember="INVOICES";
DataGrid1.DataKeyField= "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

private void lnkByName_Click(object sender, System.EventArgs e)
{
sqlSelectCommand2.Parameters["@n"].Value=txtName.Text;

// Different data set
sqlDataAdapter2.Fill(dsByName1); DataGrid1.DataSource=
dsByName1;
DataGrid1.DataMember="INVOICES";
DataGrid1.DataKeyField= "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

Is smthg wrong with this code? Will the data grid not work if I bound it to
a different data set on different link button clicks?


Your code above should run fine, but here is something a little leaner
and easier to debug:

<code>
private void BindData(string sqlQuery, string paramName, object paramValue)
{
DataTable queryTable = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, connection);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
if(paramName != null && paramValue != null)
{
sda.SelectCommand.Paramaters.Add(paramName, paramValue);
}
sda.Fill(queryTable);
DataGrid1.DataSource = queryTable;
DataGrid1.DataKeyField = "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}
</code>

Then, elsewhere in your code, all you would have to do to populate your
datagrid is to just call

private void lnkByName_Click(object sender, System.EventArgs e)
{
// sqlSelectCommand2.Parameters["@n"].Value=txtName.Text;
// // Different data set
// sqlDataAdapter2.Fill(dsByName1);
// DataGrid1.DataSource= dsByName1;
// DataGrid1.DataMember="INVOICES";
// DataGrid1.DataKeyField= "ORDER_NO";
// DataGrid1.AutoGenerateColumns=true;
// DataGrid1.DataBind();

//Replace above with:
BindData("<stored proc name>", "@n", txtName.Text);
}

Thanks


hth,
~d

Jul 21 '05 #4
Hi pmud,

Sorry about the delay in getting back to you, I was out sick.

Anyhow, when you call "BindData("dob.usp_Order", "@OrderNo",
int.Parse(txtOrder.Text));" drop the dbo. in the stored procedure name.
For some reason that I have yet to find out, SqlServer/MSDE has issues
when using owner.spname conventions.

HTH,
~d

pmud wrote:
Hi D.W. Warlock,

I created a stored procedure which works fine when i run it from the server
explorer.

Stored Procedure Code::
CREATE PROCEDURE dbo.usp_Order (@OrderNo int) AS
select * from IRUS_INVOICES where ORDER_NO = @OrderNo
GO

& then I used the followng code...
private void BindData(string sqlQuery, string paramName, object paramValue)
{
DataTable queryTable = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, sqlConnection1);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
if(paramName != null && paramValue != null)
{
//sda.SelectCommand.Paramaters.Add(paramName, paramValue);
sda.SelectCommand.Parameters.Add(paramName, paramValue);
}
sda.Fill(queryTable);
DataGrid1.DataSource = queryTable;
DataGrid1.DataKeyField = "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

private void lnkByOrder_Click(object sender, System.EventArgs e)
{
BindData("dbo.usp_Order", "@OrderNo",
int.Parse(txtOrder.Text));

}

But when I click the view link , the data grid doesnt show up the records
... What is wrong with the code?

"D.W. Warlock" wrote:

pmud wrote:
Hi,

I need to display columns in a data grid based on 7 different queries. Now I
have 32 questions:

1. Is it possble to have 1 single data adapter with 7 queries & 1 data set
or do I need to have a separate data adapter & a separate data set for each
select query?
If thats possible then how?


Yes, you can have 1 single adapter with 7 different queries and 1 data
set. It all depends on how your stored procedure is written. If there
are 7 select statements or unions or whatever, you will get back 7
tables in one stored procedure call that you can then populate into a
data set using the data adapter.

2. I have the following code which allows the user to enter an order number
& click the view button which should show all information for that
order...But the data gris is not showing the infomation, it is showing the
only the column headings... I am using only 1 data grid for all the
queries... Everytime a different view link (related to a different criteria)
is clicked , I change the DataSource , DataKeyField & DataMember for the grid
which points to a separate data set.

Code ::

private void LinkButton1_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(dsAllAO1);
DataGrid1.DataBind();
}
private void lnkByOrder_Click(object sender, System.EventArgs e)
{
sqlSelectCommand2.Parameters["@o"].Value=txtOrder.Text;

// Different data set
sqlDataAdapter2.Fill(dsByOrder1); DataGrid1.DataSource=
dsByOrder1;
DataGrid1.DataMember="INVOICES";
DataGrid1.DataKeyField= "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

private void lnkByName_Click(object sender, System.EventArgs e)
{
sqlSelectCommand2.Parameters["@n"].Value=txtName.Text;

// Different data set
sqlDataAdapter2.Fill(dsByName1); DataGrid1.DataSource=
dsByName1;
DataGrid1.DataMember="INVOICES";
DataGrid1.DataKeyField= "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

Is smthg wrong with this code? Will the data grid not work if I bound it to
a different data set on different link button clicks?


Your code above should run fine, but here is something a little leaner
and easier to debug:

<code>
private void BindData(string sqlQuery, string paramName, object paramValue)
{
DataTable queryTable = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, connection);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
if(paramName != null && paramValue != null)
{
sda.SelectCommand.Paramaters.Add(paramName, paramValue);
}
sda.Fill(queryTable);
DataGrid1.DataSource = queryTable;
DataGrid1.DataKeyField = "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}
</code>

Then, elsewhere in your code, all you would have to do to populate your
datagrid is to just call

private void lnkByName_Click(object sender, System.EventArgs e)
{
// sqlSelectCommand2.Parameters["@n"].Value=txtName.Text;
// // Different data set
// sqlDataAdapter2.Fill(dsByName1);
// DataGrid1.DataSource= dsByName1;
// DataGrid1.DataMember="INVOICES";
// DataGrid1.DataKeyField= "ORDER_NO";
// DataGrid1.AutoGenerateColumns=true;
// DataGrid1.DataBind();

//Replace above with:
BindData("<stored proc name>", "@n", txtName.Text);
}

Thanks


hth,
~d

Jul 21 '05 #5
Hi ,

I hope you are well now.Thanks for the answer ... Is there a way to sort the
data grid using the following code...coz here i have not used a data set but
a data table for binding to the data grid...I searched many articles but all
were for binding to the dat set using a data vierw only & more over I am
BINDING THE GRID on DIFFERENT LINK BUTTON CLICKS to ONE DATA TABLE WHICH
CONTAINS DIFFERENT VALUES BASED ON DIFFERENT STORED PROCEDURES....

MY code :

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

private void BindData(string sqlQuery, string paramName, object paramValue)
{
DataTable queryTable = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, sqlConnection1);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
if(paramName != null && paramValue != null)
{

sda.SelectCommand.Parameters.Add(paramName, paramValue);
}
sda.Fill(queryTable);
DataGrid1.DataSource = queryTable;
DataGrid1.DataKeyField = "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}
private void BindData(string sqlQuery, string paramName, object
paramValue,string paramName1, object paramValue1)
{
DataTable queryTable = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, sqlConnection1);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
if(paramName != null && paramValue != null && paramName1 != null &&
paramValue1 != null)
{

sda.SelectCommand.Parameters.Add(paramName, paramValue);
sda.SelectCommand.Parameters.Add(paramName1,paramV alue1);
}
sda.Fill(queryTable);
DataGrid1.DataSource = queryTable;
DataGrid1.DataKeyField = "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

private void LinkButton1_Click(object sender, System.EventArgs e)
{
BindData("dbo.usp_MasterBrowser_ViewAll",null,null );
}

private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{

}

private void lnkByOrder_Click(object sender, System.EventArgs e)
{
BindData("dbo.usp_Order", "@OrderNo", int.Parse(txtOrder.Text));

}

private void lnkByDate_Click(object sender, System.EventArgs e)
{
BindData("dbo.usp_MasterBrowser_Date","@StartDate" ,
System.DateTime.Parse(txtStartDate.Text),"@EndDate ",System.DateTime.Parse(txtEndDate.Text));
}

private void lnkByStatus_Click(object sender, System.EventArgs e)
{
BindData("dbo.usp_MasterBrowser_Status","@Status", ddlStatus.SelectedValue);
}
How can sorting be done in this grid? Is it even possible?

"D0tN3t C0d3r" wrote:
Hi pmud,

Sorry about the delay in getting back to you, I was out sick.

Anyhow, when you call "BindData("dob.usp_Order", "@OrderNo",
int.Parse(txtOrder.Text));" drop the dbo. in the stored procedure name.
For some reason that I have yet to find out, SqlServer/MSDE has issues
when using owner.spname conventions.

HTH,
~d

pmud wrote:
Hi D.W. Warlock,

I created a stored procedure which works fine when i run it from the server
explorer.

Stored Procedure Code::
CREATE PROCEDURE dbo.usp_Order (@OrderNo int) AS
select * from IRUS_INVOICES where ORDER_NO = @OrderNo
GO

& then I used the followng code...
private void BindData(string sqlQuery, string paramName, object paramValue)
{
DataTable queryTable = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, sqlConnection1);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
if(paramName != null && paramValue != null)
{
//sda.SelectCommand.Paramaters.Add(paramName, paramValue);
sda.SelectCommand.Parameters.Add(paramName, paramValue);
}
sda.Fill(queryTable);
DataGrid1.DataSource = queryTable;
DataGrid1.DataKeyField = "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

private void lnkByOrder_Click(object sender, System.EventArgs e)
{
BindData("dbo.usp_Order", "@OrderNo",
int.Parse(txtOrder.Text));

}

But when I click the view link , the data grid doesnt show up the records
... What is wrong with the code?

"D.W. Warlock" wrote:

pmud wrote:

Hi,

I need to display columns in a data grid based on 7 different queries. Now I
have 32 questions:

1. Is it possble to have 1 single data adapter with 7 queries & 1 data set
or do I need to have a separate data adapter & a separate data set for each
select query?
If thats possible then how?

Yes, you can have 1 single adapter with 7 different queries and 1 data
set. It all depends on how your stored procedure is written. If there
are 7 select statements or unions or whatever, you will get back 7
tables in one stored procedure call that you can then populate into a
data set using the data adapter.
2. I have the following code which allows the user to enter an order number
& click the view button which should show all information for that
order...But the data gris is not showing the infomation, it is showing the
only the column headings... I am using only 1 data grid for all the
queries... Everytime a different view link (related to a different criteria)
is clicked , I change the DataSource , DataKeyField & DataMember for the grid
which points to a separate data set.

Code ::

private void LinkButton1_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(dsAllAO1);
DataGrid1.DataBind();
}
private void lnkByOrder_Click(object sender, System.EventArgs e)
{
sqlSelectCommand2.Parameters["@o"].Value=txtOrder.Text;

// Different data set
sqlDataAdapter2.Fill(dsByOrder1); DataGrid1.DataSource=
dsByOrder1;
DataGrid1.DataMember="INVOICES";
DataGrid1.DataKeyField= "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

private void lnkByName_Click(object sender, System.EventArgs e)
{
sqlSelectCommand2.Parameters["@n"].Value=txtName.Text;

// Different data set
sqlDataAdapter2.Fill(dsByName1); DataGrid1.DataSource=
dsByName1;
DataGrid1.DataMember="INVOICES";
DataGrid1.DataKeyField= "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}

Is smthg wrong with this code? Will the data grid not work if I bound it to
a different data set on different link button clicks?

Your code above should run fine, but here is something a little leaner
and easier to debug:

<code>
private void BindData(string sqlQuery, string paramName, object paramValue)
{
DataTable queryTable = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, connection);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
if(paramName != null && paramValue != null)
{
sda.SelectCommand.Paramaters.Add(paramName, paramValue);
}
sda.Fill(queryTable);
DataGrid1.DataSource = queryTable;
DataGrid1.DataKeyField = "ORDER_NO";
DataGrid1.AutoGenerateColumns=true;
DataGrid1.DataBind();
}
</code>

Then, elsewhere in your code, all you would have to do to populate your
datagrid is to just call

private void lnkByName_Click(object sender, System.EventArgs e)
{
// sqlSelectCommand2.Parameters["@n"].Value=txtName.Text;
// // Different data set
// sqlDataAdapter2.Fill(dsByName1);
// DataGrid1.DataSource= dsByName1;
// DataGrid1.DataMember="INVOICES";
// DataGrid1.DataKeyField= "ORDER_NO";
// DataGrid1.AutoGenerateColumns=true;
// DataGrid1.DataBind();

//Replace above with:
BindData("<stored proc name>", "@n", txtName.Text);
}
Thanks
hth,
~d

Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jordan O'Hare | last post by:
Hello Everyone, I am after some help with the following: I have a windows application that contains a list box and two data grids. All three controls are binded to a dataset that contains...
1
by: Eagle | last post by:
I have a form that has one record with 22 fields. A grid is not the answer, either several small tables or combinations of textboxes and labels, so the user can edit all the editable fields then...
1
by: Jim | last post by:
I have a datagrid on a windows form that is filled using a data adapter and dataset created in code. I have mapped columns to the various fields. The user enters new infromation into the grid and...
5
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to...
6
by: Mike Wilson | last post by:
Dear Group, I have a heirarchical set of database tables, say - "order" and "order_type" and want to display a series of orders in a grid control, and in place of the order_type foreign key...
3
by: Scottie_do | last post by:
I have a 20meg in-memory stack-based array and I'd like to normalise in the client's memory... then add foriegn keys, and display results on a datagrid. I discovered that converting the stack to a...
5
by: Kent Boogaart | last post by:
Hi, I have some hierarchical data (FAQs) that I would like to bind to. The basic structure is: FAQ Category + Categories + FAQs So an FAQ category has any number of sub-categories and any...
5
by: Brian P. Hammer | last post by:
I have data from multiple SQL tables, some of the tables will only have one row, while others multiple rows. I load a bunch of data from the various tables and add them to a third party grid. With...
6
by: =?Utf-8?B?bXIgcGVhbnV0?= | last post by:
How do I turn on the visual grid in the web (asp) design environment. I know this is stupid but it's counterintuitive to me.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.