Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
04-07-2011, 08:17 AM #1
- Join Date
- Apr 2011
- Thanked 0 Times in 0 Posts
Error in Code in program using vb.net and Ms Access
iam working with vb.net and ms access i have a error in the below coding
Private Sub Save_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save_Button.Click
If Code_TextBox.Text <> "" And Name_TextBox.Text <> "" Then
'Dim conn As New SqlConnection(connstr)
Dim code, Name As String
code = Code_TextBox.Text
Name = Name_TextBox.Text
str = "insert into Table1 values(" & code & "," & Name & ")"
cmd = New OleDbCommand(str, cn)
cmd.ExecuteNonQuery() -------> The error is "No value given for one or more required parameters."
MsgBox("Fields cannot be empty")
04-07-2011, 03:11 PM #2
- Join Date
- Mar 2006
- St. Catharines, Ontario Canada
- Thanked 148 Times in 139 Posts
You are posting in a forum to do with MySQL. I'll move your thread to the general database forum, though you are likely best to find an Access forum to ask your question.
04-11-2011, 09:27 PM #3
That query would only be legal if *BOTH* of the following applied:Code:str = "insert into Table1 values(" & code & "," & Name & ")"
(a) Your TABLE1 has only two fields in it.
(b) Those two fields are *BOTH* numeric fields. That is, they will never hold text values, only numeric data.
[Well, not quite true. You *could* have three fields in the table *if* one of the fields is an autoincrement field.]
*PROBABLY* your query needs to look like this:
where you replace field1 and field2 with the actual names of the fields.Code:str = "insert into Table1 (field1, field2) values(" & code & ",'" & Name & "')"
And if field1 (the field that will receive the code value) is NOT numeric, then you would need apostrophes around code as well, thus:
Though this would work, it is *NOT* the best way to create and use queries in VB.NET and ADO.NET. You really need to go look at how to create parameterized queries with the OleDbCommand object and start using them.Code:str = "insert into Table1 (field1, field2) values('" & code & "','" & Name & "')"
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.