Private Sub Butp_Click(sender As Object, e As EventArgs) Handles Butp.Click
If confirm("คุณจะเพิ่มสมาชิก ใช้ หรือ ไหม") = vbNo Then Return
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
msg_error("กรุณากรอกให้ครบ")
Return
End If
If Not IsNumeric(TextBox1.Text) Or Not IsNumeric(TextBox2.Text) Then
msg_error("กรอกตัวเลขเท่านั้น")
Return
End If
sql = "insert into sell values (@IDsell_sell,@name_sell,@email_sell,@number_sell,@image_sell,@ID_list_pro)"
command = New SqlClient.SqlCommand(sql, connection)
command.Parameters.Clear()
'command.Parameters.AddWithValue("a", TextBox1.Text)
command.Parameters.AddWithValue("IDsell_sell", TextBox2.Text)
command.Parameters.AddWithValue("name_sell", TextBox3.Text)
command.Parameters.AddWithValue("email_sell", TextBox4.Text)
command.Parameters.AddWithValue("number_sell", TextBox5.Text)
command.Parameters.AddWithValue("ID_list_pro", TextBox6.Text)
If Not pic_add.Image Is Nothing Then
Dim mem As New IO.MemoryStream
pic_add.Image.Save(mem, Imaging.ImageFormat.Bmp)
Dim pic_for_add() As Byte
pic_for_add = mem.ToArray()
command.Parameters.AddWithValue("image_sell", pic_for_add)
End If
If command.ExecuteNonQuery = 0 Then
msg_error("เพิ่มไม่สำเร็จ")
Else
msg_ok("เพิ่มสำเร็จ")
refres_coffee()
get_number()
clear_from()
End If
End Sub
sql = "insert into sell values (@IDsell_sell,@name_sell,@email_sell,@number_sell,@image_sell,@ID_list_pro)"
command = New SqlClient.SqlCommand(sql, connection)
command.Parameters.Clear()
'command.Parameters.AddWithValue("a", TextBox1.Text)
command.Parameters.AddWithValue("IDsell_sell", TextBox2.Text)
command.Parameters.AddWithValue("name_sell", TextBox3.Text)
command.Parameters.AddWithValue("email_sell", TextBox4.Text)
command.Parameters.AddWithValue("number_sell", TextBox5.Text)
command.Parameters.AddWithValue("ID_list_pro", TextBox6.Text)
If Not pic_add.Image Is Nothing Then
Dim mem As New IO.MemoryStream
pic_add.Image.Save(mem, Imaging.ImageFormat.Bmp)
Dim pic_for_add() As Byte
pic_for_add = mem.ToArray()
command.Parameters.AddWithValue("image_sell", pic_for_add)
End If
If command.ExecuteNonQuery = 0 Then
msg_error("เพิ่มไม่สำเร็จ")
Else
msg_ok("เพิ่มสำเร็จ")
refres_coffee()
get_number()
clear_from()
End If
แก้ไข
Code (VB.NET)
sql = "insert into sell (IDsell_sell,name_sell,email_sell,number_sell,image_sell,ID_list_pro)values (@IDsell_sell,@name_sell,@email_sell,@number_sell,@image_sell,@ID_list_pro)"
command = New SqlClient.SqlCommand(sql, connection)
command.Parameters.Clear()
'command.Parameters.AddWithValue("a", TextBox1.Text)
command.Parameters.AddWithValue("@IDsell_sell", TextBox2.Text)
command.Parameters.AddWithValue("@name_sell", TextBox3.Text)
command.Parameters.AddWithValue("@email_sell", TextBox4.Text)
command.Parameters.AddWithValue("@number_sell", TextBox5.Text)
command.Parameters.AddWithValue("@ID_list_pro", TextBox6.Text)
If Not pic_add.Image Is Nothing Then
Dim mem As New IO.MemoryStream
pic_add.Image.Save(mem, Imaging.ImageFormat.Bmp)
Dim pic_for_add() As Byte
pic_for_add = mem.ToArray()
command.Parameters.AddWithValue("@image_sell", pic_for_add)
Dim ssss as Integer
ssss = command.ExecuteNonQuery
If ssss = 0 Then
msg_error("เพิ่มไม่สำเร็จ")
Else
msg_ok("เพิ่มสำเร็จ")
refres_coffee()
get_number()
clear_from()
End If
sql = "insert into sell (IDsell_sell,name_sell,email_sell,number_sell,image_sell,ID_list_pro)values (@IDsell_sell,@name_sell,@email_sell,@number_sell,@image_sell,@ID_list_pro)"
command = New SqlClient.SqlCommand(sql, connection)
'command.Parameters.Clear()
'command.Parameters.AddWithValue("a", TextBox1.Text)
command.Parameters.AddWithValue("@IDsell_sell", TextBox2.Text)
command.Parameters.AddWithValue("@name_sell", TextBox3.Text)
command.Parameters.AddWithValue("@email_sell", TextBox4.Text)
command.Parameters.AddWithValue("@number_sell", TextBox5.Text)
command.Parameters.AddWithValue("@ID_list_pro", TextBox6.Text)
If Not pic_add.Image Is Nothing Then
Dim mem As New IO.MemoryStream
pic_add.Image.Save(mem, Imaging.ImageFormat.Bmp)
Dim pic_for_add() As Byte
pic_for_add = mem.ToArray()
command.Parameters.AddWithValue("@image_sell", pic_for_add)
connection.open() '<-------ตัวเปิดการเชื่อมต่อฐานข้อมูล
Dim ssss as Integer
ssss = command.ExecuteNonQuery
If ssss = 0 Then
msg_error("เพิ่มไม่สำเร็จ")
Else
msg_ok("เพิ่มสำเร็จ")
refres_coffee()
get_number()
clear_from()
End If