منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : استفسار
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السلام عليكم ورحمة الله وبركاته
لدي كود حفظ تالي يحفظ البيانات لكن في حالة عدم اختيار صورة من اداة pictures box  يظهر خطا 
اريد حتا في حالة عدم اختيار صورة يحفظ بيانات 
لاريد فكره وهيا جعل صورة افتراضيه في اداة pictures box  
هل من طريقه 
كود :
  If fullname.Text = "" Then
           MessageBox.Show("الرجاء ادخال اسم العميل")

           Exit Sub
       End If


       Dim sql = "select *from tbl_customers where cus_id=N'" & Val(customer_code.Text) & "'"
       Dim adp As New SqlDataAdapter(sql, Module1.con)
       Dim ds As New DataSet
       adp.Fill(ds)
       Dim dt = ds.Tables(0)
       If dt.Rows.Count > 0 Then
           MessageBox.Show("اسم عميل موجود مسبقا")
       Else

           Dim DR = dt.NewRow
           DR!CUS_ID = customer_code.Text
           DR!FullName = fullname.Text
           DR!TEL = tel.Text
           DR!Email = email.Text
           DR!country = ComboBox1.Text
           DR!city = ComboBox2.Text
           DR!status = True
           If ofd.FileName <> "" Then
               Dim imgbytearray() As Byte
               Dim stream As New MemoryStream
               PictureBox1.Image.Save(stream, ImageFormat.Jpeg)
               imgbytearray = stream.ToArray()
               stream.Close()
               DR!picture = imgbytearray


           End If
           dt.Rows.Add(DR)
           Dim cmd As New SqlCommandBuilder(adp)
           adp.Update(dt)

           MessageBox.Show("تم حفظ بنجاح")

           btn_close_Click(sender, e)
       End If
كود :
Dim command As New SqlCommand("INSERT INTO table_name (image_column) VALUES (@image)", connection)
command.Parameters.AddWithValue("@image", DBNull.Value)
command.ExecuteNonQuery()

كود :
If PictureBox1.Image Is Nothing Then
   Dim command As New SqlCommand("INSERT INTO table_name (image_column) VALUES (@image)", connection)
   command.Parameters.AddWithValue("@image", DBNull.Value)
   command.ExecuteNonQuery()
Else
   ' code to insert the image
End If
(28-01-23, 11:36 PM)aljzazy كتب : [ -> ]
كود :
Dim command As New SqlCommand("INSERT INTO table_name (image_column) VALUES (@image)", connection)
command.Parameters.AddWithValue("@image", DBNull.Value)
command.ExecuteNonQuery()

كود :
If PictureBox1.Image Is Nothing Then
   Dim command As New SqlCommand("INSERT INTO table_name (image_column) VALUES (@image)", connection)
   command.Parameters.AddWithValue("@image", DBNull.Value)
   command.ExecuteNonQuery()
Else
   ' code to insert the image
End If

قمت بكتابة كود لكن يظهر خطا موضح في صوره 
هدا كود 
PHP كود :
If fullname.Text "" Then
            MessageBox
.Show("الرجاء ادخال اسم العميل")

 
           Exit Sub
        End 
If


 
       Dim sql "select *from tbl_customers where cus_id=N'" Val(customer_code.Text) & "'"
 
       Dim adp As New SqlDataAdapter(sqlModule1.con)
 
       Dim ds As New DataSet
        adp
.Fill(ds)
 
       Dim dt ds.Tables(0)
 
       If dt.Rows.Count 0 Then
            MessageBox
.Show("اسم عميل موجود مسبقا")
 
       Else

            Dim DR 
dt.NewRow
            DR
!CUS_ID customer_code.Text
            DR
!FullName fullname.Text
            DR
!TEL tel.Text
            DR
!Email email.Text
            DR
!country ComboBox1.Text
            DR
!city ComboBox2.Text
            DR
!status True
            If PictureBox1
.Image Is Nothing Then
                Dim command 
As New SqlCommand("INSERT INTO tbl_customers (picture) VALUES (@image)"Module1.con)
 
               command.Connection Module1.con
                command
.Parameters.AddWithValue("@image"DBNull.Value)
 
               command.ExecuteNonQuery()
 
           Else
                If ofd
.FileName <> "" Then
                    Dim imgbytearray
() As Byte
                    Dim stream 
As New MemoryStream
                    PictureBox1
.Image.Save(streamImageFormat.Jpeg)
 
                   imgbytearray stream.ToArray()
 
                   stream.Close()
 
                   DR!picture imgbytearray


                End 
If
 
               dt.Rows.Add(DR)
 
               Dim cmd As New SqlCommandBuilder(adp)
 
               adp.Update(dt)

 
               MessageBox.Show("تم حفظ بنجاح")

 
               btn_close_Click(sendere)
 
           End If

 
       End If 
افتح الاتصال قبل اجراء command.executeNonQuery ثم اغلقه بعد تنفيذ الامر 

كود :
If Con.State = 1 Then Con.Close()
        Con.Open()
        Cmd.ExecuteNonQuery()
        Con.Close()
(27-01-23, 08:22 PM)ali_ahmed12 كتب : [ -> ]السلام عليكم ورحمة الله وبركاته
لدي كود حفظ تالي يحفظ البيانات لكن في حالة عدم اختيار صورة من اداة pictures box  يظهر خطا 
اريد حتا في حالة عدم اختيار صورة يحفظ بيانات 
لاريد فكره وهيا جعل صورة افتراضيه في اداة pictures box  
هل من طريقه 
كود :
  If fullname.Text = "" Then
           MessageBox.Show("الرجاء ادخال اسم العميل")

           Exit Sub
       End If


       Dim sql = "select *from tbl_customers where cus_id=N'" & Val(customer_code.Text) & "'"
       Dim adp As New SqlDataAdapter(sql, Module1.con)
       Dim ds As New DataSet
       adp.Fill(ds)
       Dim dt = ds.Tables(0)
       If dt.Rows.Count > 0 Then
           MessageBox.Show("اسم عميل موجود مسبقا")
       Else

           Dim DR = dt.NewRow
           DR!CUS_ID = customer_code.Text
           DR!FullName = fullname.Text
           DR!TEL = tel.Text
           DR!Email = email.Text
           DR!country = ComboBox1.Text
           DR!city = ComboBox2.Text
           DR!status = True
           If ofd.FileName <> "" Then
               Dim imgbytearray() As Byte
               Dim stream As New MemoryStream
               PictureBox1.Image.Save(stream, ImageFormat.Jpeg)
               imgbytearray = stream.ToArray()
               stream.Close()
               DR!picture = imgbytearray


           End If
           dt.Rows.Add(DR)
           Dim cmd As New SqlCommandBuilder(adp)
           adp.Update(dt)

           MessageBox.Show("تم حفظ بنجاح")

           btn_close_Click(sender, e)
       End If


باعتبار العمود CUS_ID من نوع ترقيم تلقائي وإلا قم لإضافته في الكود
PHP كود :
If fullname.Text.Trim "" Then
    MessageBox
.Show("الرجاء ادخال اسم العميل")
 
   Exit Sub
End 
If

Dim cmd As SqlCommand
If Module1.con.State <> ConnectionState.Open Then Module1.con.Open()

cmd = New SqlCommand("SELECT [CUS_ID] FROM [tbl_customers] WHERE [CUS_ID]=@cus_id"Module1.con)
cmd.Parameters.AddWithValue("@cus_id"Val(customer_code.Text))
Dim a cmd.ExecuteScalar
If IsNothing(a) = False Then
    MessageBox
.Show("اسم عميل موجود مسبقا")
Else
 
   cmd = New SqlCommand("INSERT INTO [tbl_customers] ([FullName],[TEL],[Email],[country],[city],[status],[picture]) VALUES (@fullname,@tel,@email,@country,@city,@status,@picture)"Module1.con)
 
   cmd.Parameters.AddWithValue("@FullName"fullname.Text)
 
   cmd.Parameters.AddWithValue("@tel"tel.Text)
 
   cmd.Parameters.AddWithValue("@email"email.Text)
 
   cmd.Parameters.AddWithValue("@country"ComboBox1.Text)
 
   cmd.Parameters.AddWithValue("@city"ComboBox2.Text)
 
   cmd.Parameters.AddWithValue("@status"CheckBox1.Checked)
 
   If IsNothing(PictureBox1.ImageThen
        cmd
.Parameters.Add(New SqlParameter("@picture"SqlDbType.ImageWith {.Value DBNull.Value})
 
   Else
        cmd
.Parameters.AddWithValue("@picture", New ImageConverter().ConvertTo(PictureBox1.ImageGetType(Byte())))
 
   End If

 
   Dim b cmd.ExecuteNonQuery()
 
   If b 0 Then
        MessageBox
.Show("تم حفظ بنجاح")
 
       btn_close.PerformClick()
 
   Else
        MessageBox
.Show("لم يتم الحفظ")
 
   End If
End If

Module1.con.Close()