No value given for one or more required parameters.
when i click the save button I get this error
"No value given for one or more required parameters."
my back end - Ms Access 2013
front end - Visual Basic 2010
please help me!!!!
Thank you!!!
This is the line where i get the error
Code:
cmd.ExecuteNonQuery()
Code:
Imports System.Data.OleDb
Imports System.Security.Cryptography
Imports System.IO
Public Class frmCompanyMembers
Dim conn As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim dj As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim rdr As OleDbDataReader = Nothing
Dim dtable As New DataTable
Dim con As OleDbConnection = Nothing
Dim adp As OleDbDataAdapter
Dim ds As DataSet
Dim cmd As OleDbCommand = Nothing
Dim MaxRows As Integer
Private Sub Autogenerate()
' call this sub from where ever you want to set the value to the new employee code.
' declare a variable to hold itemCode
Dim MemID As String = String.Empty
' declare a variable to hold curitemCodeNum
Dim curMemIDNum As Integer = 0
' declare a variable to hold nextitemCodeNum
Dim nextMemIDNum As Integer = 0
' declare a variable to hold addNextNumber
Dim addNextNumber As Integer = 1
Using conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Ferdinand Company.accdb")
Using cmd As OleDbCommand = conn.CreateCommand
''Select statement to select the data in the appropriate field
cmd.CommandText = ("SELECT MAX(MemberID) FROM CompanyMembers")
Try
conn.Open()
MemID = CStr(cmd.ExecuteScalar)
Catch ex As Exception
Windows.Forms.MessageBox.Show(ex.Message, "Error")
End Try
End Using
End Using
'split the returned value to keep just the number
If MemID.Contains("MI") Then
curMemIDNum = CInt(MemID.Replace("MI", ""))
End If
nextMemIDNum = curMemIDNum + addNextNumber
Me.MemberIDTextBox.Text = ("MI" & nextMemIDNum.ToString("000"))
End Sub
Private Sub Reset()
MemberIDTextBox.Text = ""
MemberNameTextBox.Text = ""
GenderComboBox.Text = ""
DesignationComboBox.Text = ""
AddressTextBox.Text = ""
TelephoneNumberMaskedTextBox.Text = ""
PictureBox1.ImageLocation = ("C:\Ferdinand\UserNo-Frame.png")
PictureBox1.Load()
DateOfBirthDateTimePicker.Value = Today
AddButtonPanel.Enabled = False
DeleteButton.Enabled = False
SaveButton.Enabled = True
MemberNameTextBox.Focus()
Autogenerate()
End Sub
Private Sub cmdbrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdbrowse.Click
With OpenFileDialog1
.InitialDirectory = "C:\Users\Chamindu\Desktop\Project\Profile Pictures"
.Filter = "All Image File (*.jpg,*.bmp,*.gif)|*.jpg;*.bmp;*.gif|Bitmaps (*.bmp)|*.bmp|GIFs (*.gif)|*.gif|JPEGs (*.jpg)|*.jpg"
.FilterIndex = 2
End With
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
With PictureBox1
.Image = Image.FromFile(Me.OpenFileDialog1.FileName)
.SizeMode = PictureBoxSizeMode.AutoSize
End With
End If
End Sub
Private Sub AddButtonPanel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButtonPanel.Click
Dim promptQuestion As DialogResult = MessageBox.Show("Confirm Adding A New Record?", "New Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If promptQuestion = Windows.Forms.DialogResult.No Then
Exit Sub
End If
Reset()
End Sub
Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
Dim promptQuestion As DialogResult = MessageBox.Show("Are you sure you want to save this record?", "Save Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If promptQuestion = Windows.Forms.DialogResult.No Then
Exit Sub
End If
If Len(Trim(MemberNameTextBox.Text)) = 0 Then
ElseIf Len(Trim(GenderComboBox.Text)) = 0 Then
ElseIf Len(Trim(DesignationComboBox.Text)) = 0 Then
ElseIf Len(Trim(AddressTextBox.Text)) = 0 Then
ElseIf Len(Trim(TelephoneNumberMaskedTextBox.Text)) = 0 Then
ElseIf Len(Trim(CStr(DateOfBirthDateTimePicker.Value))) = 0 Then
MessageBox.Show("Please Don not Leave any Field Empty. Complete Empty Fields. ", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
MemberNameTextBox.Focus()
End If
Autogenerate()
con = New OleDbConnection(dbProvider & dbSource)
con.Open()
Dim cb As String = "Insert INTO CompanyMembers (MemberID,MemberName,Gender,Designation,Address,TelephoneNumber,DateOfBirth,MembersPicture) VALUES (@c1,@c2,@c3,@c4,@c5,@c6,@c7,@c8)"
Dim MemStream As New MemoryStream
Dim DataPic_Update As Byte()
Me.PictureBox1.Image.Save(MemStream, Imaging.ImageFormat.Png)
DataPic_Update = MemStream.GetBuffer()
MemStream.Read(DataPic_Update, 0, CInt(MemStream.Length))
cmd = New OleDbCommand(cb)
cmd.Connection = con
cmd.Parameters.Add(New OleDbParameter("@c1", OleDbType.VarChar, 5, "MemberID"))
cmd.Parameters.Add(New OleDbParameter("@c2", OleDbType.VarChar, 40, "MemberName"))
cmd.Parameters.Add(New OleDbParameter("@c3", OleDbType.VarChar, 6, "Gender"))
cmd.Parameters.Add(New OleDbParameter("@c4", OleDbType.VarChar, 20, "Designation"))
cmd.Parameters.Add(New OleDbParameter("@c5", OleDbType.VarChar, 40, "Address"))
cmd.Parameters.Add(New OleDbParameter("@c6", OleDbType.VarChar, 15, "TelephoneNumber"))
cmd.Parameters.Add(New OleDbParameter("@c7", OleDbType.Date, 30, "DateOfBirth"))
cmd.Parameters("@c1").Value = MemberIDTextBox.Text
cmd.Parameters("@c2").Value = MemberNameTextBox.Text
cmd.Parameters("@c3").Value = GenderComboBox.Text
cmd.Parameters("@c4").Value = DesignationComboBox.Text
cmd.Parameters("@c5").Value = AddressTextBox.Text
cmd.Parameters("@c6").Value = TelephoneNumberMaskedTextBox.Text
cmd.Parameters("@c7").Value = DateOfBirthDateTimePicker.Value
Dim photo As OleDbParameter = New OleDbParameter("@c8", SqlDbType.Image)
photo.Value = DataPic_Update
cmd.ExecuteNonQuery()
MessageBox.Show("Member Successfully Saved", "Company Members", MessageBoxButtons.OK, MessageBoxIcon.Information)
MemberNameTextBox.Focus()
SaveButton.Enabled = False
con.Close()
End Sub
Private Sub frmCompanyMembers_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dbSource = "Data Source=|DataDirectory|\Ferdinand Company.accdb"
conn.ConnectionString = dbProvider & dbSource
conn.Open()
MemberIDTextBox.Enabled = False
End Sub
Private Sub cmdHomeScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdHomeScreen.Click
Me.Hide()
SwitchBoard.Show()
End Sub
End Class
Re: No value given for one or more required parameters.
My guess is one of these needs parameters:
Me.Validate()
Me.OrderBindingSource.EndEdit()
Put your cursor at the end of one of those statements and use the backspace to delete the right parethesis. If there are parameters you will see them listed. Or put you cursor on top of one of them and right click, then click go to defintion and see what is used.
Re: No value given for one or more required parameters.
Quote:
Originally Posted by
TysonLPrice
My guess is one of these needs parameters:
Me.Validate()
Me.OrderBindingSource.EndEdit()
Put your cursor at the end of one of those statements and use the backspace to delete the right parethesis. If there are parameters you will see them listed. Or put you cursor on top of one of them and right click, then click go to defintion and see what is used.
I'm sorry wrong code.
Code:
Imports System.Data.OleDb
Imports System.Security.Cryptography
Imports System.IO
Public Class frmCompanyMembers
Dim conn As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim dj As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim rdr As OleDbDataReader = Nothing
Dim dtable As New DataTable
Dim con As OleDbConnection = Nothing
Dim adp As OleDbDataAdapter
Dim ds As DataSet
Dim cmd As OleDbCommand = Nothing
Dim MaxRows As Integer
Private Sub Autogenerate()
' call this sub from where ever you want to set the value to the new employee code.
' declare a variable to hold itemCode
Dim MemID As String = String.Empty
' declare a variable to hold curitemCodeNum
Dim curMemIDNum As Integer = 0
' declare a variable to hold nextitemCodeNum
Dim nextMemIDNum As Integer = 0
' declare a variable to hold addNextNumber
Dim addNextNumber As Integer = 1
Using conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Ferdinand Company.accdb")
Using cmd As OleDbCommand = conn.CreateCommand
''Select statement to select the data in the appropriate field
cmd.CommandText = ("SELECT MAX(MemberID) FROM CompanyMembers")
Try
conn.Open()
MemID = CStr(cmd.ExecuteScalar)
Catch ex As Exception
Windows.Forms.MessageBox.Show(ex.Message, "Error")
End Try
End Using
End Using
'split the returned value to keep just the number
If MemID.Contains("MI") Then
curMemIDNum = CInt(MemID.Replace("MI", ""))
End If
nextMemIDNum = curMemIDNum + addNextNumber
Me.MemberIDTextBox.Text = ("MI" & nextMemIDNum.ToString("000"))
End Sub
Private Sub Reset()
MemberIDTextBox.Text = ""
MemberNameTextBox.Text = ""
GenderComboBox.Text = ""
DesignationComboBox.Text = ""
AddressTextBox.Text = ""
TelephoneNumberMaskedTextBox.Text = ""
PictureBox1.ImageLocation = ("C:\Ferdinand\UserNo-Frame.png")
PictureBox1.Load()
DateOfBirthDateTimePicker.Value = Today
AddButtonPanel.Enabled = False
DeleteButton.Enabled = False
SaveButton.Enabled = True
MemberNameTextBox.Focus()
Autogenerate()
End Sub
Private Sub cmdbrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdbrowse.Click
With OpenFileDialog1
.InitialDirectory = "C:\Users\Chamindu\Desktop\Project\Profile Pictures"
.Filter = "All Image File (*.jpg,*.bmp,*.gif)|*.jpg;*.bmp;*.gif|Bitmaps (*.bmp)|*.bmp|GIFs (*.gif)|*.gif|JPEGs (*.jpg)|*.jpg"
.FilterIndex = 2
End With
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
With PictureBox1
.Image = Image.FromFile(Me.OpenFileDialog1.FileName)
.SizeMode = PictureBoxSizeMode.AutoSize
End With
End If
End Sub
Private Sub AddButtonPanel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButtonPanel.Click
Dim promptQuestion As DialogResult = MessageBox.Show("Confirm Adding A New Record?", "New Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If promptQuestion = Windows.Forms.DialogResult.No Then
Exit Sub
End If
Reset()
End Sub
Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
Dim promptQuestion As DialogResult = MessageBox.Show("Are you sure you want to save this record?", "Save Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If promptQuestion = Windows.Forms.DialogResult.No Then
Exit Sub
End If
If Len(Trim(MemberNameTextBox.Text)) = 0 Then
ElseIf Len(Trim(GenderComboBox.Text)) = 0 Then
ElseIf Len(Trim(DesignationComboBox.Text)) = 0 Then
ElseIf Len(Trim(AddressTextBox.Text)) = 0 Then
ElseIf Len(Trim(TelephoneNumberMaskedTextBox.Text)) = 0 Then
ElseIf Len(Trim(CStr(DateOfBirthDateTimePicker.Value))) = 0 Then
MessageBox.Show("Please Don not Leave any Field Empty. Complete Empty Fields. ", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
MemberNameTextBox.Focus()
End If
Autogenerate()
con = New OleDbConnection(dbProvider & dbSource)
con.Open()
Dim cb As String = "Insert INTO CompanyMembers (MemberID,MemberName,Gender,Designation,Address,TelephoneNumber,DateOfBirth,MembersPicture) VALUES (@c1,@c2,@c3,@c4,@c5,@c6,@c7,@c8)"
Dim MemStream As New MemoryStream
Dim DataPic_Update As Byte()
Me.PictureBox1.Image.Save(MemStream, Imaging.ImageFormat.Png)
DataPic_Update = MemStream.GetBuffer()
MemStream.Read(DataPic_Update, 0, CInt(MemStream.Length))
cmd = New OleDbCommand(cb)
cmd.Connection = con
cmd.Parameters.Add(New OleDbParameter("@c1", OleDbType.VarChar, 5, "MemberID"))
cmd.Parameters.Add(New OleDbParameter("@c2", OleDbType.VarChar, 40, "MemberName"))
cmd.Parameters.Add(New OleDbParameter("@c3", OleDbType.VarChar, 6, "Gender"))
cmd.Parameters.Add(New OleDbParameter("@c4", OleDbType.VarChar, 20, "Designation"))
cmd.Parameters.Add(New OleDbParameter("@c5", OleDbType.VarChar, 40, "Address"))
cmd.Parameters.Add(New OleDbParameter("@c6", OleDbType.VarChar, 15, "TelephoneNumber"))
cmd.Parameters.Add(New OleDbParameter("@c7", OleDbType.Date, 30, "DateOfBirth"))
cmd.Parameters("@c1").Value = MemberIDTextBox.Text
cmd.Parameters("@c2").Value = MemberNameTextBox.Text
cmd.Parameters("@c3").Value = GenderComboBox.Text
cmd.Parameters("@c4").Value = DesignationComboBox.Text
cmd.Parameters("@c5").Value = AddressTextBox.Text
cmd.Parameters("@c6").Value = TelephoneNumberMaskedTextBox.Text
cmd.Parameters("@c7").Value = DateOfBirthDateTimePicker.Value
Dim photo As OleDbParameter = New OleDbParameter("@c8", SqlDbType.Image)
photo.Value = DataPic_Update
cmd.ExecuteNonQuery()
MessageBox.Show("Member Successfully Saved", "Company Members", MessageBoxButtons.OK, MessageBoxIcon.Information)
MemberNameTextBox.Focus()
SaveButton.Enabled = False
con.Close()
End Sub
Private Sub frmCompanyMembers_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dbSource = "Data Source=|DataDirectory|\Ferdinand Company.accdb"
conn.ConnectionString = dbProvider & dbSource
conn.Open()
MemberIDTextBox.Enabled = False
End Sub
Private Sub cmdHomeScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdHomeScreen.Click
Me.Hide()
SwitchBoard.Show()
End Sub
End Class
Re: No value given for one or more required parameters.
Any particular line of code?
Re: No value given for one or more required parameters.
This is the line where i get the error
Code:
cmd.ExecuteNonQuery()
Re: No value given for one or more required parameters.
That's pretty straight forward. One of the parameters the insert is expecting is missing.
Is there a value in each of of the controls loading the parameters?
cmd.Parameters("@c1").Value = MemberIDTextBox.Text
cmd.Parameters("@c2").Value = MemberNameTextBox.Text
cmd.Parameters("@c3").Value = GenderComboBox.Text
cmd.Parameters("@c4").Value = DesignationComboBox.Text
cmd.Parameters("@c5").Value = AddressTextBox.Text
cmd.Parameters("@c6").Value = TelephoneNumberMaskedTextBox.Text
cmd.Parameters("@c7").Value = DateOfBirthDateTimePicker.Value
Like maybe nothing in a textbox...
Re: No value given for one or more required parameters.
You're not binding the command to a datatable... so your parameter creation is over kill...
Just use .AddWithValue...
Code:
' -- remove these lines
'cmd.Parameters.Add(New OleDbParameter("@c1", OleDbType.VarChar, 5, "MemberID"))
'cmd.Parameters.Add(New OleDbParameter("@c2", OleDbType.VarChar, 40, "MemberName"))
'cmd.Parameters.Add(New OleDbParameter("@c3", OleDbType.VarChar, 6, "Gender"))
'cmd.Parameters.Add(New OleDbParameter("@c4", OleDbType.VarChar, 20, "Designation"))
'cmd.Parameters.Add(New OleDbParameter("@c5", OleDbType.VarChar, 40, "Address"))
'cmd.Parameters.Add(New OleDbParameter("@c6", OleDbType.VarChar, 15, "TelephoneNumber"))
'cmd.Parameters.Add(New OleDbParameter("@c7", OleDbType.Date, 30, "DateOfBirth"))
'cmd.Parameters("@c1").Value = MemberIDTextBox.Text
'cmd.Parameters("@c2").Value = MemberNameTextBox.Text
'cmd.Parameters("@c3").Value = GenderComboBox.Text
'cmd.Parameters("@c4").Value = DesignationComboBox.Text
'cmd.Parameters("@c5").Value = AddressTextBox.Text
'cmd.Parameters("@c6").Value = TelephoneNumberMaskedTextBox.Text
'cmd.Parameters("@c7").Value = DateOfBirthDateTimePicker.Value
' -- Stop deleting....
' -- use this
cmd.Parameters.AddWithValue("@c1", MemberIDTextBox.Text)
cmd.Parameters.AddWithValue("@c2", MemberNameTextBox.Text)
cmd.Parameters.AddWithValue("@c3", GenderComboBox.Text)
cmd.Parameters.AddWithValue("@c4", DesignationComboBox.Text)
cmd.Parameters.AddWithValue("@c5", AddressTextBox.Text)
cmd.Parameters.AddWithValue("@c6", TelephoneNumberMaskedTextBox.Text)
cmd.Parameters.AddWithValue("@c7", DateOfBirthDateTimePicker.Value)
See if that clears up the issue... if it doesn't then go back to the original query... Access uses positional parameters, not named ones, so typically in the query you only need a ? for the place holder. When you then create the parameter, you can give it a name. Since Access will ignore it, it doesn't matter what thename is.
-tg
1 Attachment(s)
Re: No value given for one or more required parameters.
Quote:
Originally Posted by
techgnome
You're not binding the command to a datatable... so your parameter creation is over kill...
Just use .AddWithValue...
Code:
' -- remove these lines
'cmd.Parameters.Add(New OleDbParameter("@c1", OleDbType.VarChar, 5, "MemberID"))
'cmd.Parameters.Add(New OleDbParameter("@c2", OleDbType.VarChar, 40, "MemberName"))
'cmd.Parameters.Add(New OleDbParameter("@c3", OleDbType.VarChar, 6, "Gender"))
'cmd.Parameters.Add(New OleDbParameter("@c4", OleDbType.VarChar, 20, "Designation"))
'cmd.Parameters.Add(New OleDbParameter("@c5", OleDbType.VarChar, 40, "Address"))
'cmd.Parameters.Add(New OleDbParameter("@c6", OleDbType.VarChar, 15, "TelephoneNumber"))
'cmd.Parameters.Add(New OleDbParameter("@c7", OleDbType.Date, 30, "DateOfBirth"))
'cmd.Parameters("@c1").Value = MemberIDTextBox.Text
'cmd.Parameters("@c2").Value = MemberNameTextBox.Text
'cmd.Parameters("@c3").Value = GenderComboBox.Text
'cmd.Parameters("@c4").Value = DesignationComboBox.Text
'cmd.Parameters("@c5").Value = AddressTextBox.Text
'cmd.Parameters("@c6").Value = TelephoneNumberMaskedTextBox.Text
'cmd.Parameters("@c7").Value = DateOfBirthDateTimePicker.Value
' -- Stop deleting....
' -- use this
cmd.Parameters.AddWithValue("@c1", MemberIDTextBox.Text)
cmd.Parameters.AddWithValue("@c2", MemberNameTextBox.Text)
cmd.Parameters.AddWithValue("@c3", GenderComboBox.Text)
cmd.Parameters.AddWithValue("@c4", DesignationComboBox.Text)
cmd.Parameters.AddWithValue("@c5", AddressTextBox.Text)
cmd.Parameters.AddWithValue("@c6", TelephoneNumberMaskedTextBox.Text)
cmd.Parameters.AddWithValue("@c7", DateOfBirthDateTimePicker.Value)
See if that clears up the issue... if it doesn't then go back to the original query... Access uses positional parameters, not named ones, so typically in the query you only need a ? for the place holder. When you then create the parameter, you can give it a name. Since Access will ignore it, it doesn't matter what thename is.
-tg
Attachment 111867
Re: No value given for one or more required parameters.
Oddly that exposed the problem with the original code... parameter @C8... you used it in your query... you created a parameter for it, but then never added the parameter to the parameters collection... odds are, you're STILL not doing so... which brings up another question... really you want to store IMAGES inside of an Access database? what kind of images? Personally, I think that's asking for trouble. Even storing images in SQL Server needs to be done carefully... it's not something I'd ever attempt with Access.
-tg
Re: No value given for one or more required parameters.
Quote:
Originally Posted by
techgnome
Oddly that exposed the problem with the original code... parameter @C8... you used it in your query... you created a parameter for it, but then never added the parameter to the parameters collection... odds are, you're STILL not doing so... which brings up another question... really you want to store IMAGES inside of an Access database? what kind of images? Personally, I think that's asking for trouble. Even storing images in SQL Server needs to be done carefully... it's not something I'd ever attempt with Access.
-tg
I wrote the same exact code for my earlier project and it worked perfectly. the pictures that i store is in JPG or BMP format.
Re: No value given for one or more required parameters.
If it worked before, and not now, then you did something wrong... look again... you created the parameter, you set the value... but you never added the parameter to the parameters colleciton... that's why you were "Missing one or more required values"... you were missing the value for the @C8 parameter ...
-tg
Re: No value given for one or more required parameters.
please help to resolve this problem ... I am using vb2010... i want to save a image in my ms access database when i run the application it says No value given for one or more required parameters.
these are my code:
If cmbpart.Text = "" Then
MsgBox("Please fill the area below", MsgBoxStyle.Exclamation, "AVS")
ElseIf cmbcourse.Text = "" Then
MsgBox("Please fill the area below", MsgBoxStyle.Exclamation, "AVS")
ElseIf cmbpos.Text = "" Then
MsgBox("Please fill the area below", MsgBoxStyle.Exclamation, "AVS")
ElseIf txtID.Text = "" Then
MsgBox("Please fill the area below", MsgBoxStyle.Exclamation, "AVS")
ElseIf txtname.Text = "" Then
MsgBox("Please fill the area below", MsgBoxStyle.Exclamation, "AVS")
ElseIf txtbirth.Text = "" Then
MsgBox("Please fill the area below", MsgBoxStyle.Exclamation, "AVS")
ElseIf txtage.Text = "" Then
MsgBox("Please fill the area below", MsgBoxStyle.Exclamation, "AVS")
ElseIf cmbgender.Text = "" Then
MsgBox("Please fill the area below", MsgBoxStyle.Exclamation, "AVS")
ElseIf txtadd.Text = "" Then
MsgBox("Please fill the area below", MsgBoxStyle.Exclamation, "AVS")
Else
Dim save, save1 As New ADODB.Recordset
Dim save2 As New ADODB.Stream
Dim sql As String
Dim arrImage() As Byte
Dim strImage As String
Dim myMs As New IO.MemoryStream
If Not IsNothing(PictureBox1.Image) Then
PictureBox1.Image.Save(myMs, PictureBox1.Image.RawFormat)
arrImage = myMs.GetBuffer
strImage = "?"
Else
arrImage = Nothing
strImage = "NULL"
End If
sql = "insert into tblcandidates (c_pic,c_party,c_course,c_position,c_No,c_Name,c_Birth,c_age,c_gen,c_add) values (" & strImage & ",'" & cmbpart.Text & "','" & cmbcourse.Text & "','" & cmbpos.Text & "','" & txtID.Text & "','" & txtname.Text & "','" & txtbirth.Text & "','" & txtage.Text & "','" & cmbgender.Text & "','" & txtadd.Text & "')"
save1.Open(sql, con, ADODB.CursorTypeEnum.adOpenStatic)
If strImage = "?" Then
save1.Parameters.Add(strImage, OleDb.OleDbType.Binary).Value = arrImage
End If
MsgBox("Successfully save", MsgBoxStyle.Information, "AVS")
PictureBox1.Image = BackgroundImage
cmbpart.Text = ""
cmbcourse.Text = ""
cmbpos.Text = ""
txtID.Text = ""
txtname.Text = ""
txtbirth.Text = ""
txtage.Text = ""
cmbgender.Text = ""
txtadd.Text = ""
End If
End Sub
please help to resolve this problem...