خطاء عند عدم رفع الصورة في PictureBox - ابو ملاك الخبير - 27-02-18
السلام عليكم اخواني الاعزاء
لدية مشكلة في اضافة صورة الى قاعدة بيانات 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
RE: خطاء عند عدم رفع الصورة في PictureBox - ابو ملاك الخبير - 28-02-18
معقولة ولا رد خلال 24 ساعة
RE: خطاء عند عدم رفع الصورة في PictureBox - طالب برمجة - 28-02-18
PHP كود :
Private Sub TBsavecustm_Click(ByVal sender As Object, ByVal 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 ms1 As New MemoryStream If Not IsNothing(Piccustm1.Image) Then Piccustm1.Image.Save(ms1, Piccustm1.Image.RawFormat)
Dim ms2 As New MemoryStream If Not IsNothing(Piccustm2.Image) Then Piccustm2.Image.Save(ms2, Piccustm2.Image.RawFormat)
Dim ms3 As New MemoryStream If Not IsNothing(Piccustm3.Image) Then Piccustm3.Image.Save(ms3, Piccustm3.Image.RawFormat)
command.Parameters.AddWithValue("@custname", Texnamecustm.Text) command.Parameters.AddWithValue("@custadress", Texadresscustm.Text) command.Parameters.AddWithValue("@custwork", Texworkcustm.Text) command.Parameters.AddWithValue("@custmob1", Texmob1custm.Text) command.Parameters.AddWithValue("@custmob2", Texmob2custm.Text) command.Parameters.AddWithValue("@custidno", Texidcustm.Text) command.Parameters.AddWithValue("@custidwno", Texwidcustm.Text) command.Parameters.AddWithValue("@custother", Texothercustm.Text) command.Parameters.AddWithValue("@custpic1", ms1.ToArray) command.Parameters.AddWithValue("@custpic2", ms2.ToArray) command.Parameters.AddWithValue("@custpic3", ms3.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 Private Sub DGVSH_DataError(ByVal sender As Object, ByVal e As DataGridViewDataErrorEventArgs) Handles DGVSH.DataError 'اترك هذا الحدث كما هو فارغ ولا تحذفه End Sub
RE: خطاء عند عدم رفع الصورة في PictureBox - ابو ملاك الخبير - 28-02-18
(28-02-18, 04:16 AM)طالب برمجة كتب : PHP كود :
Private Sub TBsavecustm_Click(ByVal sender As Object, ByVal 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 ms1 As New MemoryStream If Not IsNothing(Piccustm1.Image) Then Piccustm1.Image.Save(ms1, Piccustm1.Image.RawFormat)
Dim ms2 As New MemoryStream If Not IsNothing(Piccustm2.Image) Then Piccustm2.Image.Save(ms2, Piccustm2.Image.RawFormat)
Dim ms3 As New MemoryStream If Not IsNothing(Piccustm3.Image) Then Piccustm3.Image.Save(ms3, Piccustm3.Image.RawFormat)
command.Parameters.AddWithValue("@custname", Texnamecustm.Text) command.Parameters.AddWithValue("@custadress", Texadresscustm.Text) command.Parameters.AddWithValue("@custwork", Texworkcustm.Text) command.Parameters.AddWithValue("@custmob1", Texmob1custm.Text) command.Parameters.AddWithValue("@custmob2", Texmob2custm.Text) command.Parameters.AddWithValue("@custidno", Texidcustm.Text) command.Parameters.AddWithValue("@custidwno", Texwidcustm.Text) command.Parameters.AddWithValue("@custother", Texothercustm.Text) command.Parameters.AddWithValue("@custpic1", ms1.ToArray) command.Parameters.AddWithValue("@custpic2", ms2.ToArray) command.Parameters.AddWithValue("@custpic3", ms3.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 Private Sub DGVSH_DataError(ByVal sender As Object, ByVal e As DataGridViewDataErrorEventArgs) Handles DGVSH.DataError 'اترك هذا الحدث كما هو فارغ ولا تحذفه End Sub
كلمات الشكر لا تكفيك ابدا
شكرا لك من القلب
|