| | |
How to show Table data in Texbox
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2007
Posts: 55
Reputation:
Solved Threads: 3
Private Sub btnExecuteReader_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExecuteReader.Click
' Create an instance of an Connection object
Dim cnn As OleDbConnection = New OleDbConnection( _
"provider=SQLOLEDB;server=localhost;uid=sa;database=pubs")
' Create instance of Command object
Dim cmd As OleDbCommand = New OleDbCommand()
txtResults.Clear()
' Set command's connection and command text
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cmd.CommandText = "select * from tablename where param1=@param1"
' Create parameter and set value
cmd.Parameters.Add(New SqlParameter("@param1", SqlDbType.Int))
cmd.Parameters("@param1").Direction = ParameterDirection.Input
cmd.Parameters("@param1").Value = Val(txtParam1.Text)
' Must open the Connection before calling ExecuteReader()
cnn.Open()
Dim reader As OleDbDataReader
reader = cmd.ExecuteReader()
While reader.Read()
txtResults.Text = txtResults.Text & reader("fname") & _
ControlChars.Tab & reader("lname") & _
ControlChars.Tab & ControlChars.Tab & _
reader("job_desc") & ControlChars.CrLf
End While
reader.Close()
cnn.Close()
End Sub
This should give you the solution to the problem
System.EventArgs) Handles btnExecuteReader.Click
' Create an instance of an Connection object
Dim cnn As OleDbConnection = New OleDbConnection( _
"provider=SQLOLEDB;server=localhost;uid=sa;database=pubs")
' Create instance of Command object
Dim cmd As OleDbCommand = New OleDbCommand()
txtResults.Clear()
' Set command's connection and command text
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cmd.CommandText = "select * from tablename where param1=@param1"
' Create parameter and set value
cmd.Parameters.Add(New SqlParameter("@param1", SqlDbType.Int))
cmd.Parameters("@param1").Direction = ParameterDirection.Input
cmd.Parameters("@param1").Value = Val(txtParam1.Text)
' Must open the Connection before calling ExecuteReader()
cnn.Open()
Dim reader As OleDbDataReader
reader = cmd.ExecuteReader()
While reader.Read()
txtResults.Text = txtResults.Text & reader("fname") & _
ControlChars.Tab & reader("lname") & _
ControlChars.Tab & ControlChars.Tab & _
reader("job_desc") & ControlChars.CrLf
End While
reader.Close()
cnn.Close()
End Sub
This should give you the solution to the problem
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Cannot retrieve data from data base
- Next Thread: Pls Help, i have a problem loading my gridview with data
| Thread Tools | Search this Thread |
"crystal .net .net2005 2008 access add advanced application array assignment basic beginner box button buttons center click code combo convert cpu data database datagrid datagridview designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall forms html image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity open pan pdf picturebox picturebox2 port print printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase sqlserver storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vba vbnet vista visual visualbasic visualbasic.net visualstudio.net web wpf wrapingcode xml





