473,396 Members | 1,877 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.

populate DataGrid from database in C#

I hv dropdownlist on a c# page connected to a database(MS Access).
I want to get values onto my datagrid when I select a value from the dropdownlist.The Item I select from the dropdown will determine what I get loaded onto the datagrid.

Please help with some code.
Expand|Select|Wrap|Line Numbers
  1. connect.ConnectionString = strng;
  2.  
  3.         OleDbCommand command = new OleDbCommand("Select * from Extensions Where FilterByKey = '" + DropDownList1.SelectedItem + "'", connect);
  4.         connect.Open();
  5.         command.Connection = connect;
  6.         datareader = command.ExecuteReader();
  7.         if (datareader.Read())
  8.         {
  9.             // This will filter database data by the FilterByKey and then populate the datagrid
  10.                  GridView1.Items.Add(datareader2[0].ToString());****not working
  11.                      LabelMessage.Text = "All values displayed";
  12.             connect.Close();
  13.             datareader.Close();
Jun 4 '07 #1
1 6507
kenobewan
4,871 Expert 4TB
I believe that you will need to use the selectedinex event. Why are you trying to filter twice this should be done by the SQL statement? Why not just add the items?
Jun 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Swadh | last post by:
Hi, I need urgent help on Windows Form datagrid. I have to Display a datagrid that has a textbox column and another one combo box column. I have two tables in my Access database as: Table 1:...
3
by: Karunakararao | last post by:
Hi All i have 40,000 records. populate the total records in Datagrid . it's taken time I need to populate the first 2000 records After the need to populate next 2000 records. how can i do...
9
by: Mike L | last post by:
I tried a sample of code in MSDN magazine, but now I'm stuck. What code has the best performance to populate a Data Grid with a SP? Below is the code I have, which might be completing the wrong...
4
by: Mike L | last post by:
I'm open for any suggestions on how to better program this. I want the user to select a license from a combo box, cboPrivilege and then the user will click the add button, then a record will be...
1
by: Simon Harris | last post by:
Hi All, I wish to populate more than one datagrid from the same OleDBCommand. The code I have is: Dim objCmd As New OleDbCommand(strSql, objConn) Then... ...
2
by: gn | last post by:
I am able to populate a datagrid from an XML variable using the following: Try Dim ds As New DataSet ds.ReadXml(New StringReader(HttpContext.Current.Application("var").ToString))...
3
by: crjunk | last post by:
I have 4 different databases that I'm having to pull data from in order to populate a datagrid. I am able to do this, but my problem is that because I'm pulling the data from 4 different...
3
by: rn5a | last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB table. The records retrieved depends upon 2 conditions (the conditions depend on what a user selects in an ASPX page). If...
1
by: Tarik Monem | last post by:
Hi everyone and I hope that you can help. I am trying to send a value of a cell within a Datagrid to my php file which has a simple sql query: here's the php: <? $server = "localhost";
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
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.