Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Displaying a selected record from Access DB in a Textbox

$
0
0
Hello,

It is a seemingly easy code but I still can not retreave what I need. Given a very simple table in an Access database (Table1), which consist of only 2 columns (employee and salary). There is a form with a combo box, a button and a textbox. I would like to be able to select employee name from the combobox and by clicking the button displaying the sorresponding salary in the textbox.

Here is the code made following a tutorial:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim conn As OleDbConnection
conn = New OleDbConnection( _
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=""C:\muki.accdb"";" & _
"Mode=Share Deny None")

conn.Open()

Dim sql As String = "select employee from Table1 where(Me.Combobox1.SelectedItem)" ' this is where I say select salary corresponding to employee chosen from combobox


Dim da As OleDbDataAdapter = New OleDbDataAdapter(sql, Conn)
Dim ds As DataSet = New DataSet

da.Fill(ds, "Table1")
Dim dt As DataTable = ds.Tables("Table1")
Dim row As DataRow
For Each row In dt.Rows
Textobox1.Text = CStr(row("salary"))
Next
Conn.Close()
End Sub


I always got the error message :No value given for one or more required parameters.

I got stuck with it and not sure what is wrong with the above code. Can someone point me to the right direction please:)
Thanks
Suhi

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>