473,473 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

A Simple SQL Result displayed into a TextBox

Hey all,

Please help I'm very new and want to learn,

I have a SQL Database with three columns, "ID" (Primary Key), "FName"
and "LName"

All I want to do to learn, is to type the ID Number in Textbox1, Click
"Submit" and the FName apprears in
Textbox2 and Lname Appears in Textbox3.

I'm Doing this in Visual Basic..

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Con1 As New SqlDataSource()
Con1.ConnectionString =
ConfigurationManager.ConnectionStrings("Test").ToS tring()
Con1.SelectCommandType = SqlDataSourceCommandType.Text
Con1.SelectCommand = "SELECT FName , LName FROM Agent WHERE ID
= 1 VALUES (@Textbox1, @Textbox2, @Textbox3)"

Con1.SelectParameters.Add("ID", Textbox1.Text)
Con1.SelectParameters.Add("FName", Textbox2.Text)
Con1.SelectParameters.Add("LName", Textbox3.Text)
End Sub = ((((((IT DOESNT" DISPLAY ANYTHING!!))))))

Dec 10 '06 #1
2 2847

You don't need the parameters to read from the database.
The VALUES clause is only used for Insert/Update.
Change Con1.SelectCommand to "SELECT FName, LName FROM Agent
WHERE ID = 1 "

Also, I haven't used SQLDataSource. Here's an example of
a way to retrieve information from SQLServer:

Dim ds As DataSet
'open the connection
Using cnn As New SqlConnection(My.Settings.ProductConnectionString)
cnn.Open()

'define the command
Dim cmd As New SqlCommand
cmd.Connection = cnn
cmd.CommandText = "SELECT * FROM Product"
'define the data adapter and fill the data table
Dim da As New SqlDataAdapter(cmd)
ds = New DataSet
da.Fill(ds, "Product")
End Using

'Read through the dataset and display the data.
For Each dr As DataRow In ds.Tables("Product").Rows
Dim ProductID As Integer = CType(dr.Item("ProductID"), Integer)
Dim ProductName As String = dr.Item("ProductName").ToString
Dim ProductNumber As String = dr.Item("ProductNumber").ToString
Dim Description As String = dr.Item("Description").ToString
Console.WriteLine(String.Format("ProductID {0}, " & _
"ProductName {1}, {2}ProductNumber {3}, " & _
"Description {4}", ProductID, ProductName, _
ControlChars.CrLf, ProductNumber, Description))
Next

HTH,
Robin S.
------------------------------------------------
<As*****@Cableone.netwrote in message
news:11**********************@n67g2000cwd.googlegr oups.com...
Hey all,

Please help I'm very new and want to learn,

I have a SQL Database with three columns, "ID" (Primary Key), "FName"
and "LName"

All I want to do to learn, is to type the ID Number in Textbox1, Click
"Submit" and the FName apprears in
Textbox2 and Lname Appears in Textbox3.

I'm Doing this in Visual Basic..

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Con1 As New SqlDataSource()
Con1.ConnectionString =
ConfigurationManager.ConnectionStrings("Test").ToS tring()
Con1.SelectCommandType = SqlDataSourceCommandType.Text
Con1.SelectCommand = "SELECT FName , LName FROM Agent WHERE ID
= 1 VALUES (@Textbox1, @Textbox2, @Textbox3)"

Con1.SelectParameters.Add("ID", Textbox1.Text)
Con1.SelectParameters.Add("FName", Textbox2.Text)
Con1.SelectParameters.Add("LName", Textbox3.Text)
End Sub = ((((((IT DOESNT" DISPLAY ANYTHING!!))))))

Dec 11 '06 #2
Thank you so much!!

I really Appreciate it!
RobinS wrote:
You don't need the parameters to read from the database.
The VALUES clause is only used for Insert/Update.
Change Con1.SelectCommand to "SELECT FName, LName FROM Agent
WHERE ID = 1 "

Also, I haven't used SQLDataSource. Here's an example of
a way to retrieve information from SQLServer:

Dim ds As DataSet
'open the connection
Using cnn As New SqlConnection(My.Settings.ProductConnectionString)
cnn.Open()

'define the command
Dim cmd As New SqlCommand
cmd.Connection = cnn
cmd.CommandText = "SELECT * FROM Product"
'define the data adapter and fill the data table
Dim da As New SqlDataAdapter(cmd)
ds = New DataSet
da.Fill(ds, "Product")
End Using

'Read through the dataset and display the data.
For Each dr As DataRow In ds.Tables("Product").Rows
Dim ProductID As Integer = CType(dr.Item("ProductID"), Integer)
Dim ProductName As String = dr.Item("ProductName").ToString
Dim ProductNumber As String = dr.Item("ProductNumber").ToString
Dim Description As String = dr.Item("Description").ToString
Console.WriteLine(String.Format("ProductID {0}, " & _
"ProductName {1}, {2}ProductNumber {3}, " & _
"Description {4}", ProductID, ProductName, _
ControlChars.CrLf, ProductNumber, Description))
Next

HTH,
Robin S.
------------------------------------------------
<As*****@Cableone.netwrote in message
news:11**********************@n67g2000cwd.googlegr oups.com...
Hey all,

Please help I'm very new and want to learn,

I have a SQL Database with three columns, "ID" (Primary Key), "FName"
and "LName"

All I want to do to learn, is to type the ID Number in Textbox1, Click
"Submit" and the FName apprears in
Textbox2 and Lname Appears in Textbox3.

I'm Doing this in Visual Basic..

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Con1 As New SqlDataSource()
Con1.ConnectionString =
ConfigurationManager.ConnectionStrings("Test").ToS tring()
Con1.SelectCommandType = SqlDataSourceCommandType.Text
Con1.SelectCommand = "SELECT FName , LName FROM Agent WHERE ID
= 1 VALUES (@Textbox1, @Textbox2, @Textbox3)"

Con1.SelectParameters.Add("ID", Textbox1.Text)
Con1.SelectParameters.Add("FName", Textbox2.Text)
Con1.SelectParameters.Add("LName", Textbox3.Text)
End Sub = ((((((IT DOESNT" DISPLAY ANYTHING!!))))))
Dec 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Oli | last post by:
Hi Folks, Alright, I have a textbox called "A" and the value in that textbox is "B". When the user presses submit I want A : B to appear on the page. How do I do it? I appreciate that this...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
12
by: Peter Proost | last post by:
Hi group, I've got what seems a simple problem, but I can't find the solution. I've got a textbox and a handheld scanner to scan barcodes, the scanner just generates keypresses like a keyboard...
5
by: Vear | last post by:
Sorry, very Newbie question here. I don't know what I'm doing wrong. I have to use a <asp:hyperlink> to go to another page. I want to pick up the value in a text box. This is what I've tried and It...
5
by: Mike | last post by:
Hello All, Please, if anyone can point me to the problem, I'd sure appreciate it! I am very new to VB programming and not a programmer to begin with. This is part of a Visual Basic 2005 Express...
1
by: chadw | last post by:
Not sure what I am missing sure its probably something very simple, I need something to get my entered text out of the textbox and entered into a database currently the code looks like this. ...
12
by: Matt F | last post by:
I'm creating simple ping script that prompts a user for various parameters. However, I would like each line of the ping displayed as it is received. Currently, the result isn't displayed until...
1
by: silpa | last post by:
I have a form named dataentry1.aspx It has Name,Age,centimetres,metres textboxes. we will enter name in name textbox,age in age textbox. when we enter height in centimetres textbox, and after...
5
by: kimiraikkonen | last post by:
Hello, I have a textbox named "textbox1" and a button named "button1" How can i retrieve the console (cmd) data into textbox? For example when i run Shell("cmd.exe /k dir...
2
by: manishamca | last post by:
can anyone say me how to find the difference of values present in two textbox and display the result in the third textbox. for eg: <input type=text name=t1 value=123> <input...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.