|
-
Apr 5th, 2010, 03:53 PM
#1
Thread Starter
Lively Member
Parameter @ID has no default value ???
Hey all,
I have a button that is supposed to display the next row in my database, however Im getting the error "Parameter @ID has no default value"
I can make my code work without parameterized queries but Im trying to make it work with them...So Im sure there is something wrong with my code, obviously
Can anyone help me out?
Code:
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
txtID.Text = txtID.Text + 1
Dim ds As New DataSet()
Dim intCurrentIndex As Integer = 0
Dim da As New OleDbDataAdapter()
Dim conn As New OleDbConnection()
Dim dr As OleDbDataReader
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mydb.mdb;"
conn.Open()
da.SelectCommand = New OleDbCommand("SELECT * FROM Log WHERE ID = @ID")
da.SelectCommand.Connection = conn
da.SelectCommand.Parameters.Add("@idate", OleDbType.DBDate, 40, "idate")
da.SelectCommand.Parameters.Add("@itime_all", OleDbType.VarChar, 40, "itime_all")
da.SelectCommand.Parameters.Add("@ishift", OleDbType.VarChar, 40, "ishift")
da.SelectCommand.Parameters.Add("@icomment", OleDbType.VarChar, 5000, "icomment")
da.SelectCommand.Parameters.Add("@icategory", OleDbType.VarChar, 200, "icategory")
da.SelectCommand.Parameters.Add("@irecipe", OleDbType.VarChar, 100, "irecipe")
da.SelectCommand.Parameters.Add("@irate", OleDbType.VarChar, 40, "irate")
da.SelectCommand.Parameters.Add("@ID", OleDbType.VarChar, 40, "ID")
dr = da.SelectCommand.ExecuteReader()
While dr.Read()
txtID.Text = da.SelectCommand.Parameters("@ID").Value
txtDate.Text = da.SelectCommand.Parameters("@idate").Value
txtTime_ALL.Text = da.SelectCommand.Parameters("@itime_all").Value
txtShift.Text = da.SelectCommand.Parameters("@ishift").Value
txtComment.Text = da.SelectCommand.Parameters("@icomment").Value
txtCategory.Text = da.SelectCommand.Parameters("@icategory").Value
txtRecipe.Text = da.SelectCommand.Parameters("@irecipe").Value
txtRate.Text = da.SelectCommand.Parameters("@irate").Value
End While
conn.Close()
End Sub
If I change my sql statement to
Code:
WHERE ID = "& txtID.Text &"
Then i can get it to work fine, but I hear that isn't good programming.
Thanks everyone.
-
Apr 5th, 2010, 04:32 PM
#2
Re: Parameter @ID has no default value ???
Try this
Code:
txtID.Text = txtID.Text + 1
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mydb.mdb;")
conn.Open()
Dim cmd = New OleDbCommand("SELECT ID,idate,itime_all,ishift,icomment,icategory,irecipe,irate FROM Log WHERE ID = @ID")
cmd.Connection = conn
cmd.Parameters.Add("@ID", OleDbType.VarChar, 40).Value = txtid.text
Dim dr As OleDbDataReader = cmd.ExecuteReader()
While dr.Read()
txtID.Text = dr.GetValue(0).ToString
txtDate.Text = dr.GetValue(1).ToString
txtTime_ALL.Text = dr.GetValue(2).ToString
txtShift.Text = dr.GetValue(3).ToString
txtComment.Text = dr.GetValue(4).ToString
txtCategory.Text = dr.GetValue(5).ToString
txtRecipe.Text = dr.GetValue(6).ToString
txtRate.Text = dr.GetValue(7).ToString
End While
conn.Close()
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
-
Apr 5th, 2010, 04:41 PM
#3
Thread Starter
Lively Member
Re: Parameter @ID has no default value ???
Awesome, Thanks, That worked.
Its similar to what I had but a little different. And of course yours worked =)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|