27-02-18, 12:37 AM
السلام عليكم اخواني الاعزاء
لدية مشكلة في اضافة صورة الى قاعدة بيانات SQL من PictureBox
حيث يحدث خطاء اذا لم اقم برفع الصورة مع المعلومات
اريد البرنامج يستمر في حالة عدم وجود صورة علما ان قيمتها في القاعدة NULL
لدية مشكلة في اضافة صورة الى قاعدة بيانات SQL من PictureBox
حيث يحدث خطاء اذا لم اقم برفع الصورة مع المعلومات
اريد البرنامج يستمر في حالة عدم وجود صورة علما ان قيمتها في القاعدة NULL
كود :
Private Sub TBsavecustm_Click(sender As Object, e As EventArgs) Handles TBsavecustm.Click
Dim command As New SqlCommand("insert into Customer(custname,custadress,custwork,custmob1,custmob2,custidno,custidwno,custother,custpic1,custpic2,custpic3) values(@custname,@custadress,@custwork,@custmob1,@custmob2,@custidno,@custidwno,@custother,@custpic1,@custpic2,@custpic3)", SQLcon)
Dim ms As New MemoryStream
Piccustm1.Image.Save(ms, Piccustm1.Image.RawFormat)
Piccustm2.Image.Save(ms, Piccustm2.Image.RawFormat)
Piccustm3.Image.Save(ms, Piccustm3.Image.RawFormat)
command.Parameters.Add("@custname", SqlDbType.NVarChar).Value = Texnamecustm.Text
command.Parameters.Add("@custadress", SqlDbType.NVarChar).Value = Texadresscustm.Text
command.Parameters.Add("@custwork", SqlDbType.NVarChar).Value = Texworkcustm.Text
command.Parameters.Add("@custmob1", SqlDbType.NVarChar).Value = Texmob1custm.Text
command.Parameters.Add("@custmob2", SqlDbType.NVarChar).Value = Texmob2custm.Text
command.Parameters.Add("@custidno", SqlDbType.NVarChar).Value = Texidcustm.Text
command.Parameters.Add("@custidwno", SqlDbType.NVarChar).Value = Texwidcustm.Text
command.Parameters.Add("@custother", SqlDbType.NVarChar).Value = Texothercustm.Text
command.Parameters.Add("@custpic1", SqlDbType.Image).Value = ms.ToArray()
command.Parameters.Add("@custpic2", SqlDbType.Image).Value = ms.ToArray()
command.Parameters.Add("@custpic3", SqlDbType.Image).Value = ms.ToArray()
' Dim DT As New DataTable
' If Not IsDBNull(DT.Rows(0).Item("@custpic1")) Then
' Dim ByteImg As Byte() = DirectCast(DT.Rows(0).Item("@custpic1"), Byte())
' End If
SQLcon.Open()
If command.ExecuteNonQuery() = 1 Then
MessageBox.Show("تمت اضافة المعلومات بنجاح..... شكرا")
Else
MessageBox.Show("لم يتم الاضافة ... لابد من جود خطاء او نقص معلومات")
End If
SQLcon.Close()
Load_Customer()
DGVSH.DataSource = dt_Customer
End Sub