Hi All.
I am new to this forum... Don't know how to start but here it goes....
I am writing in VB.net a program with one form, yet mulitple textboxes.
the data appears in each text box as A1, A2, A3, A4, A5
The database CANDYSHOP has a table CANDYSHOP with each column as
ChocolateID Chocolate SweetID Sweet DrinksID Drinks
A1 snikers B1 jelly babies C1 pepsi
A2 mars B2 wine gums C2 sprite
A3 milkyway B3 polo C3 fanta etc.....
there are no more than 20 rows
My code is
[code=vb]
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Dim CandyShopPath = Application.Sta rtupPath & "\SWEETSLIST.md b"
Dim SweetListSearch = ""
Dim ConnectCandySho pDataBase As New OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0;Data Source =" & CandyShopPath
Dim CandyShopComman d As OleDb.OleDbComm and
Dim CandyShopDataRe ader As OleDb.OleDbData Reader
Dim SWEETSQL = "SELECT Chocolate FROM CANDYSHOP WHERE ChocolateID = '" & ChocolateTextBo x.Text '& "'AND SweetID =' " & SweetTextBox.Te xt & "'AND DrinksID='" & DrinksTextBox.T ext & "'"
ConnectCandySho pDataBase.Open( ) 'Open a database connection
CandyShopComman d = New OleDb.OleDbComm and(SWEETSQL, ConnectCandySho pDataBase)
*** CandyShopDataRe ader = CandyShopComman d.ExecuteReader
If CandyShopDataRe ader.Read = True Then 'load information to relevant textboxes
ChocolateTextBo x.Text = SWEETSQL
SweetTextBox.Te xt = SWEETSQL
CrispsTextBox.T ext = SWEETSQL
DrinksTextBox.T ext = SWEETSQL
Else
ChocolateTextBo x.Text = "Error - Does Not Match code in Database"
SweetTextBox.Te xt = "Error - Does Not Match code in Database"
CrispsTextBox.T ext = "Error - Does Not Match code in Database"
DrinksTextBox.T ext = "Error - Does Not Match code in Database"
End If
CandyShopDataRe ader.Close() 'close DataReader
ConnectCandySho pDataBase.Close () 'close Database Connection
End Sub
End Class
[/code]
Q. How would i display the corrseponding data in each textbox.
ChocloateTextBo x is poulates with the value of A1, which in the databse is Snickers.
Currently it displays A1, not Snickers.
What steps do i need to take or what code is required to poulate the textbox with the product not the ID.
i think i need DataAdapter, but unsure?
Any help, answers, examples or tips would be much useful.
Many Thanks
I am new to this forum... Don't know how to start but here it goes....
I am writing in VB.net a program with one form, yet mulitple textboxes.
the data appears in each text box as A1, A2, A3, A4, A5
The database CANDYSHOP has a table CANDYSHOP with each column as
ChocolateID Chocolate SweetID Sweet DrinksID Drinks
A1 snikers B1 jelly babies C1 pepsi
A2 mars B2 wine gums C2 sprite
A3 milkyway B3 polo C3 fanta etc.....
there are no more than 20 rows
My code is
[code=vb]
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Dim CandyShopPath = Application.Sta rtupPath & "\SWEETSLIST.md b"
Dim SweetListSearch = ""
Dim ConnectCandySho pDataBase As New OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0;Data Source =" & CandyShopPath
Dim CandyShopComman d As OleDb.OleDbComm and
Dim CandyShopDataRe ader As OleDb.OleDbData Reader
Dim SWEETSQL = "SELECT Chocolate FROM CANDYSHOP WHERE ChocolateID = '" & ChocolateTextBo x.Text '& "'AND SweetID =' " & SweetTextBox.Te xt & "'AND DrinksID='" & DrinksTextBox.T ext & "'"
ConnectCandySho pDataBase.Open( ) 'Open a database connection
CandyShopComman d = New OleDb.OleDbComm and(SWEETSQL, ConnectCandySho pDataBase)
*** CandyShopDataRe ader = CandyShopComman d.ExecuteReader
If CandyShopDataRe ader.Read = True Then 'load information to relevant textboxes
ChocolateTextBo x.Text = SWEETSQL
SweetTextBox.Te xt = SWEETSQL
CrispsTextBox.T ext = SWEETSQL
DrinksTextBox.T ext = SWEETSQL
Else
ChocolateTextBo x.Text = "Error - Does Not Match code in Database"
SweetTextBox.Te xt = "Error - Does Not Match code in Database"
CrispsTextBox.T ext = "Error - Does Not Match code in Database"
DrinksTextBox.T ext = "Error - Does Not Match code in Database"
End If
CandyShopDataRe ader.Close() 'close DataReader
ConnectCandySho pDataBase.Close () 'close Database Connection
End Sub
End Class
[/code]
Q. How would i display the corrseponding data in each textbox.
ChocloateTextBo x is poulates with the value of A1, which in the databse is Snickers.
Currently it displays A1, not Snickers.
What steps do i need to take or what code is required to poulate the textbox with the product not the ID.
i think i need DataAdapter, but unsure?
Any help, answers, examples or tips would be much useful.
Many Thanks
Comment