'Is there a fix to my into statement error?
This is my code
Private Sub Guna2Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Guna2Button1.Click
Dim pop As OpenFileDialog = New OpenFileDialog
If pop.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
Guna2CirclePictureBox1.Image = Image.FromFile(pop.FileName)
End If
End Sub
Sub save()
Try
conn.Open()
Dim cmd As New OleDb.OleDbCommand("insert into Table1('firstname','lastname','username','password','dob','role','status','pic') values(@firstname,@lastname,@username,@password,@dob,@role,@status,@pic)", conn)
Dim i As New Integer
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@firstname", Guna2TextBox1.Text)
cmd.Parameters.AddWithValue("@lastname", Guna2TextBox2.Text)
cmd.Parameters.AddWithValue("@username", Guna2TextBox3.Text)
cmd.Parameters.AddWithValue("@password", Guna2TextBox4.Text)
cmd.Parameters.AddWithValue("@dob", CDate(Guna2DateTimePicker1.Value))
cmd.Parameters.AddWithValue("@role", Guna2ComboBox1.Text)
cmd.Parameters.AddWithValue("@status", CBool(Guna2CheckBox2.Checked.ToString))
'image convert to binary formate
Dim FileSize As UInt32
Dim mstream As New System.IO.MemoryStream
Guna2CirclePictureBox1.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim picture() As Byte = mstream.GetBuffer
FileSize = mstream.Length
mstream.Close()
cmd.Parameters.AddWithValue("@pic", picture)
i = cmd.ExecuteNonQuery
If i > 0 Then
MsgBox("You are now a registered member.", vbInformation)
Else
MsgBox("Registration Failed. Try Again.", vbCritical)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Close()
End Sub
It says type "firstname" correctly but I did. It is also the same field name in my access database. I hope you could help me with my problem. I promise to be responsive. Thank you.
Solution 1:[1]
Also, Password is a reserved word:
"insert into Table1(firstname,lastname,username,[password],dob,role,[status],pic) values(@firstname,@lastname,@username,@password,@dob,@role,@status,@pic)"
and DateTimePicker returns a DateTime value:
cmd.Parameters.AddWithValue("@dob", Guna2DateTimePicker1.Value)
cmd.Parameters.AddWithValue("@status", Guna2CheckBox2.Checked)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
