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_Cli ck(object sender, System.EventArg s e)
{
sqlDataAdapter1 .Fill(dsAllAO1) ;
DataGrid1.DataB ind();
}
private void lnkByOrder_Clic k(object sender, System.EventArg s e)
{
sqlSelectComman d2.Parameters["@o"].Value=txtOrder .Text;
// Different data set
sqlDataAdapter2 .Fill(dsByOrder 1); DataGrid1.DataS ource=
dsByOrder1;
DataGrid1.DataM ember="INVOICES ";
DataGrid1.DataK eyField= "ORDER_NO";
DataGrid1.AutoG enerateColumns= true;
DataGrid1.DataB ind();
}
private void lnkByName_Click (object sender, System.EventArg s e)
{
sqlSelectComman d2.Parameters["@n"].Value=txtName. Text;
// Different data set
sqlDataAdapter2 .Fill(dsByName1 ); DataGrid1.DataS ource=
dsByName1;
DataGrid1.DataM ember="INVOICES ";
DataGrid1.DataK eyField= "ORDER_NO";
DataGrid1.AutoG enerateColumns= true;
DataGrid1.DataB ind();
}
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 5 2478
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_Cli ck(object sender, System.EventArg s e) { sqlDataAdapter1 .Fill(dsAllAO1) ; DataGrid1.DataB ind(); }
private void lnkByOrder_Clic k(object sender, System.EventArg s e) { sqlSelectComman d2.Parameters["@o"].Value=txtOrder .Text;
// Different data set sqlDataAdapter2 .Fill(dsByOrder 1); DataGrid1.DataS ource= dsByOrder1; DataGrid1.DataM ember="INVOICES "; DataGrid1.DataK eyField= "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); }
private void lnkByName_Click (object sender, System.EventArg s e) { sqlSelectComman d2.Parameters["@n"].Value=txtName. Text;
// Different data set sqlDataAdapter2 .Fill(dsByName1 ); DataGrid1.DataS ource= dsByName1; DataGrid1.DataM ember="INVOICES "; DataGrid1.DataK eyField= "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); }
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.SelectComma nd.CommandType = CommandType.Sto redProcedure;
if(paramName != null && paramValue != null)
{
sda.SelectComma nd.Paramaters.A dd(paramName, paramValue);
}
sda.Fill(queryT able);
DataGrid1.DataS ource = queryTable;
DataGrid1.DataK eyField = "ORDER_NO";
DataGrid1.AutoG enerateColumns= true;
DataGrid1.DataB ind();
}
</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.EventArg s e)
{
// sqlSelectComman d2.Parameters["@n"].Value=txtName. Text;
// // Different data set
// sqlDataAdapter2 .Fill(dsByName1 );
// DataGrid1.DataS ource= dsByName1;
// DataGrid1.DataM ember="INVOICES ";
// DataGrid1.DataK eyField= "ORDER_NO";
// DataGrid1.AutoG enerateColumns= true;
// DataGrid1.DataB ind();
//Replace above with:
BindData("<stor ed proc name>", "@n", txtName.Text);
} Thanks
hth,
~d
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_Cli ck(object sender, System.EventArg s e) { sqlDataAdapter1 .Fill(dsAllAO1) ; DataGrid1.DataB ind(); }
private void lnkByOrder_Clic k(object sender, System.EventArg s e) { sqlSelectComman d2.Parameters["@o"].Value=txtOrder .Text;
// Different data set sqlDataAdapter2 .Fill(dsByOrder 1); DataGrid1.DataS ource= dsByOrder1; DataGrid1.DataM ember="INVOICES "; DataGrid1.DataK eyField= "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); }
private void lnkByName_Click (object sender, System.EventArg s e) { sqlSelectComman d2.Parameters["@n"].Value=txtName. Text;
// Different data set sqlDataAdapter2 .Fill(dsByName1 ); DataGrid1.DataS ource= dsByName1; DataGrid1.DataM ember="INVOICES "; DataGrid1.DataK eyField= "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); }
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.SelectComma nd.CommandType = CommandType.Sto redProcedure; if(paramName != null && paramValue != null) { sda.SelectComma nd.Paramaters.A dd(paramName, paramValue); } sda.Fill(queryT able); DataGrid1.DataS ource = queryTable; DataGrid1.DataK eyField = "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); } </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.EventArg s e) { // sqlSelectComman d2.Parameters["@n"].Value=txtName. Text; // // Different data set // sqlDataAdapter2 .Fill(dsByName1 ); // DataGrid1.DataS ource= dsByName1; // DataGrid1.DataM ember="INVOICES "; // DataGrid1.DataK eyField= "ORDER_NO"; // DataGrid1.AutoG enerateColumns= true; // DataGrid1.DataB ind();
//Replace above with: BindData("<stor ed proc name>", "@n", txtName.Text); }
Thanks
hth, ~d
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.SelectComma nd.CommandType = CommandType.Sto redProcedure;
if(paramName != null && paramValue != null)
{
//sda.SelectComma nd.Paramaters.A dd(paramName, paramValue);
sda.SelectComma nd.Parameters.A dd(paramName, paramValue);
}
sda.Fill(queryT able);
DataGrid1.DataS ource = queryTable;
DataGrid1.DataK eyField = "ORDER_NO";
DataGrid1.AutoG enerateColumns= true;
DataGrid1.DataB ind();
}
private void lnkByOrder_Clic k(object sender, System.EventArg s e)
{
BindData("dbo.u sp_Order", "@OrderNo",
int.Parse(txtOr der.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_Cli ck(object sender, System.EventArg s e) { sqlDataAdapter1 .Fill(dsAllAO1) ; DataGrid1.DataB ind(); }
private void lnkByOrder_Clic k(object sender, System.EventArg s e) { sqlSelectComman d2.Parameters["@o"].Value=txtOrder .Text;
// Different data set sqlDataAdapter2 .Fill(dsByOrder 1); DataGrid1.DataS ource= dsByOrder1; DataGrid1.DataM ember="INVOICES "; DataGrid1.DataK eyField= "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); }
private void lnkByName_Click (object sender, System.EventArg s e) { sqlSelectComman d2.Parameters["@n"].Value=txtName. Text;
// Different data set sqlDataAdapter2 .Fill(dsByName1 ); DataGrid1.DataS ource= dsByName1; DataGrid1.DataM ember="INVOICES "; DataGrid1.DataK eyField= "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); }
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.SelectComma nd.CommandType = CommandType.Sto redProcedure; if(paramName != null && paramValue != null) { sda.SelectComma nd.Paramaters.A dd(paramName, paramValue); } sda.Fill(queryT able); DataGrid1.DataS ource = queryTable; DataGrid1.DataK eyField = "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); } </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.EventArg s e) { // sqlSelectComman d2.Parameters["@n"].Value=txtName. Text; // // Different data set // sqlDataAdapter2 .Fill(dsByName1 ); // DataGrid1.DataS ource= dsByName1; // DataGrid1.DataM ember="INVOICES "; // DataGrid1.DataK eyField= "ORDER_NO"; // DataGrid1.AutoG enerateColumns= true; // DataGrid1.DataB ind();
//Replace above with: BindData("<stor ed proc name>", "@n", txtName.Text); }
Thanks
hth, ~d
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(txtOr der.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.SelectComma nd.CommandType = CommandType.Sto redProcedure; if(paramName != null && paramValue != null) { //sda.SelectComma nd.Paramaters.A dd(paramName, paramValue); sda.SelectComma nd.Parameters.A dd(paramName, paramValue); } sda.Fill(queryT able); DataGrid1.DataS ource = queryTable; DataGrid1.DataK eyField = "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); }
private void lnkByOrder_Clic k(object sender, System.EventArg s e) { BindData("dbo.u sp_Order", "@OrderNo", int.Parse(txtOr der.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...Bu t 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_Cli ck(object sender, System.EventArg s e) { sqlDataAdapter1 .Fill(dsAllAO1) ; DataGrid1.DataB ind(); }
private void lnkByOrder_Clic k(object sender, System.EventArg s e) { sqlSelectComman d2.Parameters["@o"].Value=txtOrder .Text;
// Different data set sqlDataAdapter2 .Fill(dsByOrder 1); DataGrid1.DataS ource= dsByOrder1 ; DataGrid1.DataM ember="INVOICES "; DataGrid1.DataK eyField= "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); }
private void lnkByName_Click (object sender, System.EventArg s e) { sqlSelectComman d2.Parameters["@n"].Value=txtName. Text;
// Different data set sqlDataAdapter2 .Fill(dsByName1 ); DataGrid1.DataS ource= dsByName1; DataGrid1.DataM ember="INVOICES "; DataGrid1.DataK eyField= "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); }
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.SelectComma nd.CommandType = CommandType.Sto redProcedure; if(paramName != null && paramValue != null) { sda.SelectComma nd.Paramaters.A dd(paramName, paramValue); } sda.Fill(queryT able); DataGrid1.DataS ource = queryTable; DataGrid1.DataK eyField = "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); } </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.EventArg s e) { // sqlSelectComman d2.Parameters["@n"].Value=txtName. Text; // // Different data set // sqlDataAdapter2 .Fill(dsByName1 ); // DataGrid1.DataS ource= dsByName1; // DataGrid1.DataM ember="INVOICES "; // DataGrid1.DataK eyField= "ORDER_NO"; // DataGrid1.AutoG enerateColumns= true; // DataGrid1.DataB ind();
//Replace above with: BindData("<stor ed proc name>", "@n", txtName.Text); }
Thanks
hth, ~d
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(objec t sender, System.EventArg s 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.SelectComma nd.CommandType = CommandType.Sto redProcedure;
if(paramName != null && paramValue != null)
{
sda.SelectComma nd.Parameters.A dd(paramName, paramValue);
}
sda.Fill(queryT able);
DataGrid1.DataS ource = queryTable;
DataGrid1.DataK eyField = "ORDER_NO";
DataGrid1.AutoG enerateColumns= true;
DataGrid1.DataB ind();
}
private void BindData(string sqlQuery, string paramName, object
paramValue,stri ng paramName1, object paramValue1)
{
DataTable queryTable = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter( sqlQuery, sqlConnection1) ;
sda.SelectComma nd.CommandType = CommandType.Sto redProcedure;
if(paramName != null && paramValue != null && paramName1 != null &&
paramValue1 != null)
{
sda.SelectComma nd.Parameters.A dd(paramName, paramValue);
sda.SelectComma nd.Parameters.A dd(paramName1,p aramValue1);
}
sda.Fill(queryT able);
DataGrid1.DataS ource = queryTable;
DataGrid1.DataK eyField = "ORDER_NO";
DataGrid1.AutoG enerateColumns= true;
DataGrid1.DataB ind();
}
private void LinkButton1_Cli ck(object sender, System.EventArg s e)
{
BindData("dbo.u sp_MasterBrowse r_ViewAll",null ,null);
}
private void DataGrid1_SortC ommand(object source,
System.Web.UI.W ebControls.Data GridSortCommand EventArgs e)
{
}
private void lnkByOrder_Clic k(object sender, System.EventArg s e)
{
BindData("dbo.u sp_Order", "@OrderNo", int.Parse(txtOr der.Text));
}
private void lnkByDate_Click (object sender, System.EventArg s e)
{
BindData("dbo.u sp_MasterBrowse r_Date","@Start Date",
System.DateTime .Parse(txtStart Date.Text),"@En dDate",System.D ateTime.Parse(t xtEndDate.Text) );
}
private void lnkByStatus_Cli ck(object sender, System.EventArg s e)
{
BindData("dbo.u sp_MasterBrowse r_Status","@Sta tus",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(txtOr der.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.SelectComma nd.CommandType = CommandType.Sto redProcedure; if(paramName != null && paramValue != null) { //sda.SelectComma nd.Paramaters.A dd(paramName, paramValue); sda.SelectComma nd.Parameters.A dd(paramName, paramValue); } sda.Fill(queryT able); DataGrid1.DataS ource = queryTable; DataGrid1.DataK eyField = "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); }
private void lnkByOrder_Clic k(object sender, System.EventArg s e) { BindData("dbo.u sp_Order", "@OrderNo", int.Parse(txtOr der.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...Bu t 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_Cli ck(object sender, System.EventArg s e) { sqlDataAdapter1 .Fill(dsAllAO1) ; DataGrid1.DataB ind(); }
private void lnkByOrder_Clic k(object sender, System.EventArg s e) { sqlSelectComman d2.Parameters["@o"].Value=txtOrder .Text;
// Different data set sqlDataAdapter2 .Fill(dsByOrder 1); DataGrid1.DataS ource= dsByOrder1 ; DataGrid1.DataM ember="INVOICES "; DataGrid1.DataK eyField= "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); }
private void lnkByName_Click (object sender, System.EventArg s e) { sqlSelectComman d2.Parameters["@n"].Value=txtName. Text;
// Different data set sqlDataAdapter2 .Fill(dsByName1 ); DataGrid1.DataS ource= dsByName1; DataGrid1.DataM ember="INVOICES "; DataGrid1.DataK eyField= "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); }
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.SelectComma nd.CommandType = CommandType.Sto redProcedure; if(paramName != null && paramValue != null) { sda.SelectComma nd.Paramaters.A dd(paramName, paramValue); } sda.Fill(queryT able); DataGrid1.DataS ource = queryTable; DataGrid1.DataK eyField = "ORDER_NO"; DataGrid1.AutoG enerateColumns= true; DataGrid1.DataB ind(); } </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.EventArg s e) { // sqlSelectComman d2.Parameters["@n"].Value=txtName. Text; // // Different data set // sqlDataAdapter2 .Fill(dsByName1 ); // DataGrid1.DataS ource= dsByName1; // DataGrid1.DataM ember="INVOICES "; // DataGrid1.DataK eyField= "ORDER_NO"; // DataGrid1.AutoG enerateColumns= true; // DataGrid1.DataB ind();
//Replace above with: BindData("<stor ed proc name>", "@n", txtName.Text); }
Thanks
hth, ~d This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 five tables, and three relations that I want
to take advantage of. Everything works fine however I want
to use the data grid table style editor to make...
|
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 click on Save. I cannot use a
grid because then it scrolls across the screen forever and ever.
So my questions are: How would I use a repeater to...
|
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 then clicks a save button on
the toolbar to save the updated or new data. Two questions:
1. How do I let the user move directly from the row of...
|
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 have a separate data adapter & a separate data set for each
select query?
If thats possible then how?
|
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 identifier, I would like a dropdown combo box
(lookup from the "order_type" table) to change the type of the order. I also
need an update command...
| |
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 datatable my memory utilisation
increases to 120 megs. (lots of overhead)
Couple of questions
1)- Is that memory increase typical? All I want to...
|
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 number of FAQs.
|
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 some of the rows, I perform
calculations on some of the rows and all this is loaded into the grid as
well. I am trying to figure out the best way...
|
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.
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |