473,569 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populate Unbound Data Grid View via Text Box values

294 Contributor
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 2267
mcupito
294 Contributor
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
3313
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 way to populate a data grid. I like using code and not the server explorer. (I replaced the sa password for this post.) private void...
2
4257
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 columns collection and look at the poperties of an individual column the name property is not in the list. Is there a way to change (or even find) the...
0
4156
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 "inizialize" the Data Grid View (add a data sorce, filled with notthing at staratup, and hide some columns) when i put a code in the txtCLCOD textbox start a...
2
2782
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 language is c++
0
1743
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 data displayed in the 'data grid view' to a text file (.txt). can anyone help me on this? really appreciate your help. anyway, im using vb.net. thanx in...
2
3193
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 is not shown because the column width is not large enough. Is there a way I can fix that in the data grid view? I see a column height property but...
0
1076
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
2734
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 source contains lots of columns and some of these i do not want to show on the grid. Is there a property/option where i can just get my specified...
1
1992
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. Means once we enter any value in any text box, that value is shown in "total" text box. I just attached image also.. Small change , i just removed...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
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, 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. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
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...
0
3657
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...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
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
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.