473,322 Members | 1,526 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,322 software developers and data experts.

Populate Unbound Data Grid View via Text Box values

294 256MB
I am trying to populate a data grid view based off of two text boxes, Start date and End date.

I am not sure how to work with DataGridViews or DataSets.
So if textbox1.text = x/x/2013 and textbox2.text = y/y/2014, then clicking a button will filter the records and display only those records with corresponding date values in the data grid view.

The biggest part I am struggling with is getting the records via search button. Here's what I have so far:

Expand|Select|Wrap|Line Numbers
  1.                 Dim SQLConnection As New SqlConnection("Data Source=SQLTEST_HR,4000\SQLEXPRESS;Integrated Security=True")
  2.         Dim SqlCommand As New SqlCommand
  3.         Dim SQLReader As SqlDataReader
  4.         Dim dt As New DataTable
  5.  
  6.         'Dim SqlCommand As New SqlCommand("Select * FROM PARTICIPANT WHERE FIRST_NM_TXT = " & Trim(SearchFirsttxt.Text) & "'", SQLConnection)
  7.  
  8.         SqlCommand.Connection = SQLConnection
  9.         SQLConnection.Open()
  10.         SqlCommand.CommandText = "Select * FROM PARTICIPANT WHERE FIRST_NM_TXT = '" & Trim(SearchFirsttxt.Text) & "' and LAST_NM_TXT = '" & SearchLastTxt.Text & "'"
  11.         Dim myAdapter As New SqlDataAdapter(SqlCommand)
  12.         myAdapter.Fill(dt)
  13.         DataGridView1.DataSource(dt)
  14.  
  15.         SQLConnection.Close()
Any ideas on what should follow?

Thanks
Jan 10 '14 #1
1 2254
mcupito
294 256MB
I figured it out. Here is my solution for anyone wondering how to do the same thing.

Expand|Select|Wrap|Line Numbers
  1.         Dim SQLConnection As New SqlConnection("Your Connection String Here")
  2.         Dim SqlCommand As New SqlCommand
  3.         'Dim SQLReader As SqlDataReader
  4.         Dim dt As New DataTable
  5.  
  6.         SQLConnection.Open() 'Opens database Connection
  7.         SqlCommand.Connection = SQLConnection 'Assigns command to the connection
  8.         SqlCommand.CommandText = "Select * FROM PARTICIPANT WHERE FIRST_NM_TXT = '" & SearchFirsttxt.Text & "' and LAST_NM_TXT = '" & SearchLastTxt.Text & "';"
  9.         'SQL Command returns rows where values in database and textboxes are equal
  10.         Dim myAdapter As New SqlDataAdapter(SqlCommand) 'holds the data
  11.         myAdapter.Fill(dt) 'datatable that is populated into the holder (DataAdapter)
  12.         DataGridView1.DataSource = dt 'Assigns source of information to the gridview (DataTable)
  13.         SQLConnection.Close() 'Closes Connection for security measures
Jan 10 '14 #2

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

Similar topics

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...
2
by: Joe Griffith | last post by:
I'm using a Win Forms Data Grid View control in unbound mode. When I add columns using the wizard the first item is the column name. Everything works fine. However, if you return to the...
0
by: Gian Paolo | last post by:
this is something really i can't find a reason. I have a form with a tabcontrol with tree pages, in the second page there is a Data GRid View. Plus i have a class. When i open the form i...
2
by: Dilanka | last post by:
I want to double click on the particular data item in data grid view and get that those values to another form can somebody tell me how can i do this? i'm using visual studio .net 2005 and the...
0
by: nanaalwi | last post by:
hi there, im doing a project right now to download a data from EEPROM of a camcorder. i used a 'data grid view' to display all the data downloaded from the camcorder. however, i have to save the...
2
by: jakeesgirl | last post by:
I'm creating a C# program in Visual Studio. When I query the sql database, the results are put into a data grid view. However, the column widths are always too small when displayed. I have text that...
0
by: enrico via DotNetMonster.com | last post by:
how do i change the values in a particular column in my data grid view? -- Message posted via http://www.dotnetmonster.com
0
by: cadab | last post by:
I have a data grid view, i have specified several columns through the designer that i would like to show on the grid, i have mapped them to the datasource, this works fine, the problem is, my data...
1
by: Muralikrishna | last post by:
Hi, How to add(sum) grid view text boxes. I was designed one grid view, in that grid view there is 7 text boxes in single row, i need to calculate total of these text box values dynamically....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.