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

نسخة كاملة : الشرط لا يتنفذ بشكل كامل في عملية جلب اسم المنتج
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
مرحبا يا شباب

 اريد جلب اسم المنتج عند ادخال رقم الباركود لكن عندما يكون الرقم موجود لا يفعل شي ولا يجلب الاسم و عندما لا يوجد منتج يتم تنفيذ جزء اظهار رسالة التنبيه
الكود .

كود :
If e.KeyCode = Keys.Enter Then
           Try
             
               cmd = New OleDb.OleDbCommand("select Pro_Name from TBL_Products where Pro_Code = " & txtprocode.Text, con)
               con.Open()
               Dim drr As OleDb.OleDbDataReader = cmd.ExecuteReader
               If drr.HasRows Then
                   txtdes.Text = drr(0)



               Else
                   MsgBox("This Product Not Found !", MsgBoxStyle.Exclamation, "Sorry !!")
                   txtprocode.Clear()
                   txtdes.Clear()
                   txtqu.Clear()
                   txtmoms.Clear()
                   txtPris.Clear()
                   txtrbt.Clear()
                   txttotalt.Clear()

                   txtprocode.Focus()

               End If
               drr.Close()



           Catch ex As Exception
               Exit Sub

           Finally
               con.Close()
           End Try

       End If

 Pro_Name : اسم المنتج
pro_Code : كود المنتج

مع العلم ترتيب الاعمدة بالجدول :
Pro_ID
Pro_Code
Pro_Name

txtdes : هو تكتست بوكس لاظهار اسم المنتج
(23-02-19, 03:25 AM)georgos كتب : [ -> ]مرحبا يا شباب

 اريد جلب اسم المنتج عند ادخال رقم الباركود لكن عندما يكون الرقم موجود لا يفعل شي ولا يجلب الاسم و عندما لا يوجد منتج يتم تنفيذ جزء اظهار رسالة التنبيه
الكود .

كود :
If e.KeyCode = Keys.Enter Then
           Try
             
               cmd = New OleDb.OleDbCommand("select Pro_Name from TBL_Products where Pro_Code = " & txtprocode.Text, con)
               con.Open()
               Dim drr As OleDb.OleDbDataReader = cmd.ExecuteReader
               If drr.HasRows Then
                   txtdes.Text = drr(0)



               Else
                   MsgBox("This Product Not Found !", MsgBoxStyle.Exclamation, "Sorry !!")
                   txtprocode.Clear()
                   txtdes.Clear()
                   txtqu.Clear()
                   txtmoms.Clear()
                   txtPris.Clear()
                   txtrbt.Clear()
                   txttotalt.Clear()

                   txtprocode.Focus()

               End If
               drr.Close()



           Catch ex As Exception
               Exit Sub

           Finally
               con.Close()
           End Try

       End If

 Pro_Name : اسم المنتج
pro_Code : كود المنتج

مع العلم ترتيب الاعمدة بالجدول :
Pro_ID
Pro_Code
Pro_Name

txtdes : هو تكتست بوكس لاظهار اسم المنتج

أولاً : عدل هذا السطر :

كود :
                cmd = New OleDb.OleDbCommand("select Pro_Name from TBL_Products where Pro_Code = " & txtprocode.Text & " ", con)


ثانياً : هل الحقل Pro_Code رقمي او نصي ؟

اذا رقمي الكود سليم .

إذا نصي يجب تعديله كالتالي :


كود :
                cmd = New OleDb.OleDbCommand("select Pro_Name from TBL_Products where Pro_Code = '" & txtprocode.Text & "'" , con)
pro_code رقمي
ونفس المشكلة ال else تتنفذ لكن
كود :
 txtdes.Text = drr(0)

لا تتفذ
جرب هذا الكود إذا لم ينجح ضع مثالا مصغرا عن البرنامج أي فورم مختصر مع قاعدة البيانات .

PHP كود :
Dim StrSQL as string "select Pro_Name from TBL_Products where Pro_Code = " CInt(txtprocode.Text
 If 
Con.State ConnectionState.Closed Then Con.Open()
 
Dim da As New OleDbDataAdapter(StrSQLcon)
 
Dim dt As New DataTable
 da
.Fill(dt)
 If 
Con.State ConnectionState.Open Then Con.Close()
 
txtdes.Text dt.rows(0)("Pro_Name").ToString 
مرحباً اخى الفاضل

فى البداية تعال على السطر التالى
كود :
Exit Sub

واستبدله بـ 
كود :
               MsgBox(ex.Message)

حتى تظهر معك رسالة الخطاء ووضعها هنا لتوضح معنا اين تقع المشكلة لديك

تحياتى لك
وتمنياتى لك التوفيق
لم تنجح Sad
فقط قم باستبدال الكود كاملاً بهذا الكود
كود :
       If e.KeyCode = Keys.Enter Then
           'Get product info
           Dim StrSQL As String = "select Pro_Name from TBL_Products where Pro_Code = " & CInt(txtprocode.Text)
           Dim da As New OleDbDataAdapter(StrSQL, con)
           Dim dt As New DataTable
           da.Fill(dt)
           If dt.Rows.Count <> 0 Then
               txtdes.Text = dt.Rows(0)("Pro_Name").ToString
           Else
               MsgBox("This Product Not Found !", MsgBoxStyle.Exclamation, "Sorry !!")
               txtprocode.Clear()
               txtdes.Clear()
               txtqu.Clear()
               txtmoms.Clear()
               txtPris.Clear()
               txtrbt.Clear()
               txttotalt.Clear()

               txtprocode.Focus()
           End If
       End If

وسيتم حل مشكلة ظهور الرسالة بمجرد الكتابة

تحياتى لك
وتمنياتى لك التوفيق
شكرا لك اخي الكريم
الشكر لله والحمد لله
والحمد لله على كل حال

تحياتى لك
وتمنياتى لك التوفيق