| Home | Forums | Reviews | Articles | Register |
![]() |
| Thread Tools | Rate Thread |
|
|
|
| |
|
D.W. Warlock
Guest
Posts: n/a
|
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 |
|
||
|
||||
|
=?Utf-8?B?cG11ZA==?=
Guest
Posts: n/a
|
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 > |
|
||
|
||||
|
=?Utf-8?B?cG11ZA==?=
Guest
Posts: n/a
|
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 > |
|
||
|
||||
|
D0tN3t C0d3r
Guest
Posts: n/a
|
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 >> |
|
||
|
||||
|
=?Utf-8?B?cG11ZA==?=
Guest
Posts: n/a
|
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,paramValue1); } 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.DataGridSortCommandEventArgs 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 > >> > |
|
||
|
||||
|
|
|
| |
![]() |
| Thread Tools | |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Flex Grid Questions for Peter Hibbs | Joshua | Microsoft Access Form Coding | 0 | 22nd Apr 2008 09:02 PM |
| How to Add the Data grid and How to load the Grid? | =?Utf-8?B?S2FydGhpa2V5YW4gUGVyaWFzYW15?= | Microsoft Access Form Coding | 3 | 2nd Jul 2007 03:02 PM |
| Grid View / Data Grid | =?Utf-8?B?TWFyY28=?= | Microsoft Access Forms | 4 | 3rd May 2007 06:03 PM |
| A Couple of questions about the Property Grid | chris.dannemiller@gmail.com | Microsoft C# .NET | 2 | 18th Jun 2006 05:02 PM |
| A couple of Data Grid questions | =?Utf-8?B?bWtsYXBw?= | Microsoft ASP .NET | 4 | 15th Mar 2004 01:56 PM |
Powered by vBulletin®. Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2010, Crawlability, Inc. |




