تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] ممكن المساعدة في اجراء بحث كومبوبكس وتيكست
#1
السلام عليكم ورحمة الله وبركاته :-
الاساتذة الاعزاء انا جديد في عالم البرمجة لذا اتبع شروحات لتكوين برنامج
في احد الاجرائات المستخدمة يكون الشرح على بأستخدام MySQL
انا اطبق الشرح على SqlServer
لم احصل على النتيجة كما في الشرح

الفكرة انه لدي كومبوبوكس اختار منه طريقة البحث بواسطة الباركود او الاسم او الشركة
وفي التيكست بوكس يكتب الباركود او الاسم او الشركة ليتم البحث عنه

الكود المستخدم هوة

cn.Open()
cm = New SqlCommand("SELECT * FROM tblProduct AS p INNER JOIN tblGeneric AS g ON p.ProductGeneric = GenericID INNER JOIN tblBrand AS b ON p.ProductBrand = BrandID INNER JOIN tblFromulation AS f ON p.ProductFromulation = FromulationID INNER JOIN tblClassification AS c ON p.ProductClassification = ClassificationID INNER JOIN tblType AS t ON p.ProductType = TypeID where ProductQuantity > 0 and " & cboFilter.Text & " like '" & txtSearch.Text & "'", cn)
dr = cm.ExecuteReader

الخطأ

[/url]System.data.sqlclient.sqlexception: 'incorrect syntax near the keyword 'like'.'

[url=https://www.codeproject.com/Questions/5385211/System-data-sqlclient-sqlexception-incorrect-synta]
الرد }}}
تم الشكر بواسطة:
#2
جرب هذا 
PHP كود :
cn.Open()
Dim filterColumn As String cboFilter.Text
Dim searchText 
As String txtSearch.Text


Dim validColumns 
As New List(Of StringFrom {"Column1""Column2""Column3"' استبدل Column1, Column2, Column3 بأسماء الأعمدة الفعلية

If validColumns.Contains(filterColumn) Then
    Dim query As String = "SELECT * FROM tblProduct AS p " &
                          "INNER JOIN tblGeneric AS g ON p.ProductGeneric = GenericID " &
                          "INNER JOIN tblBrand AS b ON p.ProductBrand = BrandID " &
                          "INNER JOIN tblFromulation AS f ON p.ProductFromulation = FromulationID " &
                          "INNER JOIN tblClassification AS c ON p.ProductClassification = ClassificationID " &
                          "INNER JOIN tblType AS t ON p.ProductType = TypeID " &
                          "WHERE ProductQuantity > 0 AND " & filterColumn & " LIKE @searchText"

    cm = New SqlCommand(query, cn)
    cm.Parameters.AddWithValue("@searchText", "%" & searchText & "%")

    dr = cm.ExecuteReader()
Else
    MessageBox.Show("Invalid filter column selected.")
End If 
[صورة مرفقة: images?q=tbn:ANd9GcT72OLJW7D1E5QW-HUeWeJ...TGoNeg2jnQ]
الرد }}}
تم الشكر بواسطة:
#3
(15-07-24, 10:05 AM)تركي الحلواني كتب : جرب هذا 
PHP كود :
cn.Open()
Dim filterColumn As String cboFilter.Text
Dim searchText 
As String txtSearch.Text


Dim validColumns 
As New List(Of StringFrom {"Column1""Column2""Column3"' استبدل Column1, Column2, Column3 بأسماء الأعمدة الفعلية

If validColumns.Contains(filterColumn) Then
    Dim query As String = "SELECT * FROM tblProduct AS p " &
                          "INNER JOIN tblGeneric AS g ON p.ProductGeneric = GenericID " &
                          "INNER JOIN tblBrand AS b ON p.ProductBrand = BrandID " &
                          "INNER JOIN tblFromulation AS f ON p.ProductFromulation = FromulationID " &
                          "INNER JOIN tblClassification AS c ON p.ProductClassification = ClassificationID " &
                          "INNER JOIN tblType AS t ON p.ProductType = TypeID " &
                          "WHERE ProductQuantity > 0 AND " & filterColumn & " LIKE @searchText"

    cm = New SqlCommand(query, cn)
    cm.Parameters.AddWithValue("@searchText", "%" & searchText & "%")

    dr = cm.ExecuteReader()
Else
    MessageBox.Show("Invalid filter column selected.")
End If 

شكرا جزيلا سوف اجرب ان شاء الله
الرد }}}
تم الشكر بواسطة:
#4
(15-07-24, 10:14 AM)raedre22 كتب :
(15-07-24, 10:05 AM)تركي الحلواني كتب : جرب هذا 
PHP كود :
cn.Open()
Dim filterColumn As String cboFilter.Text
Dim searchText 
As String txtSearch.Text


Dim validColumns 
As New List(Of StringFrom {"Column1""Column2""Column3"' استبدل Column1, Column2, Column3 بأسماء الأعمدة الفعلية

If validColumns.Contains(filterColumn) Then
    Dim query As String = "SELECT * FROM tblProduct AS p " &
                          "INNER JOIN tblGeneric AS g ON p.ProductGeneric = GenericID " &
                          "INNER JOIN tblBrand AS b ON p.ProductBrand = BrandID " &
                          "INNER JOIN tblFromulation AS f ON p.ProductFromulation = FromulationID " &
                          "INNER JOIN tblClassification AS c ON p.ProductClassification = ClassificationID " &
                          "INNER JOIN tblType AS t ON p.ProductType = TypeID " &
                          "WHERE ProductQuantity > 0 AND " & filterColumn & " LIKE @searchText"

    cm = New SqlCommand(query, cn)
    cm.Parameters.AddWithValue("@searchText", "%" & searchText & "%")

    dr = cm.ExecuteReader()
Else
    MessageBox.Show("Invalid filter column selected.")
End If 

شكرا جزيلا سوف اجرب ان شاء الله
الاخ تركي للتوضيح لم يعمل لدي الكود
للتوضيح كود البحث يعرض على داتا جرد فيو هذا الكود كامل

  Sub LoadRecords()
      Dim i As Integer = 0
      Dim total As Double = 0
      DataGridView1.Rows.Clear()
      cn.Open()
      cm = New SqlCommand("SELECT * FROM tblProduct AS p INNER JOIN tblGeneric AS g ON p.ProductGeneric = GenericID INNER JOIN tblBrand AS b ON p.ProductBrand = BrandID INNER JOIN tblFromulation AS f ON p.ProductFromulation = FromulationID INNER JOIN tblClassification AS c ON p.ProductClassification = ClassificationID INNER JOIN tblType AS t ON p.ProductType = TypeID where ProductQuantity > 0 and '" & cboFilter.Text & "' like '%" & txtSearch.Text & "%'", cn)
      dr = cm.ExecuteReader
      While dr.Read
          i += 1
          total += CInt(dr.Item("ProductQuantity").ToString)
          DataGridView1.Rows.Add(i, dr.Item("ProductID").ToString, dr.Item("ProductBarcode").ToString, dr.Item("GenericName").ToString, dr.Item("BrandName").ToString, dr.Item("FromulationName").ToString, dr.Item("ClassificationName").ToString, dr.Item("TypeName").ToString, dr.Item("ProductQuantity").ToString, dr.Item("ProductBuyPrice").ToString, dr.Item("ProductSalePrice").ToString, Format(CDate(dr.Item("ProductDate").ToString), "yyyy/MM"), dr.Item("ProductReorder").ToString)
      End While
      dr.Close()
      cm = Nothing
      cn.Close()
      lblCount.Text = "  عدد المنتجات :  " & Format(CLng(DataGridView1.Rows.Count), "#,##0") & Space(10) & "  كمية المنتجات :  " & Format(total, "#,##0")
  End Sub
الرد }}}
تم الشكر بواسطة:
#5
جرب هذا 
PHP كود :
Sub LoadRecords()
 
   Dim i As Integer 0
    Dim total 
As Double 0
    DataGridView1
.Rows.Clear()

 
   cn.Open()

 
       Dim query As String "SELECT * FROM tblProduct AS p " &
 
                         "INNER JOIN tblGeneric AS g ON p.ProductGeneric = GenericID " &
 
                         "INNER JOIN tblBrand AS b ON p.ProductBrand = BrandID " &
 
                         "INNER JOIN tblFromulation AS f ON p.ProductFromulation = FromulationID " &
 
                         "INNER JOIN tblClassification AS c ON p.ProductClassification = ClassificationID " &
 
                         "INNER JOIN tblType AS t ON p.ProductType = TypeID " &
 
                         "WHERE ProductQuantity > 0 AND " cboFilter.Text " LIKE @SearchText"

 
   cm = New SqlCommand(querycn)
 
   cm.Parameters.AddWithValue("@SearchText""%" txtSearch.Text "%")

 
   dr cm.ExecuteReader()

 
    DataGridView
    While dr
.Read()
 
       i += 1
        total 
+= CInt(dr.Item("ProductQuantity").ToString())
 
       DataGridView1.Rows.Add(i
 
                              dr.Item("ProductID").ToString(), 
 
                              dr.Item("ProductBarcode").ToString(), 
 
                              dr.Item("GenericName").ToString(), 
 
                              dr.Item("BrandName").ToString(), 
 
                              dr.Item("FromulationName").ToString(), 
 
                              dr.Item("ClassificationName").ToString(), 
 
                              dr.Item("TypeName").ToString(), 
 
                              dr.Item("ProductQuantity").ToString(), 
 
                              dr.Item("ProductBuyPrice").ToString(), 
 
                              dr.Item("ProductSalePrice").ToString(), 
 
                              Format(CDate(dr.Item("ProductDate").ToString()), "yyyy/MM"), 
 
                              dr.Item("ProductReorder").ToString())
 
   End While

 
      dr.Close()
 
   cm Nothing
        cn
.Close()

 
     lblCount.Text "عدد المنتجات: " Format(CLng(DataGridView1.Rows.Count), "#,##0") & Space(10) & " كمية المنتجات: " Format(total"#,##0")
End Sub 
[صورة مرفقة: images?q=tbn:ANd9GcT72OLJW7D1E5QW-HUeWeJ...TGoNeg2jnQ]
الرد }}}
تم الشكر بواسطة:
#6
(15-07-24, 11:50 AM)تركي الحلواني كتب : جرب هذا 
PHP كود :
Sub LoadRecords()
 
   Dim i As Integer 0
    Dim total 
As Double 0
    DataGridView1
.Rows.Clear()

 
   cn.Open()

 
       Dim query As String "SELECT * FROM tblProduct AS p " &
 
                         "INNER JOIN tblGeneric AS g ON p.ProductGeneric = GenericID " &
 
                         "INNER JOIN tblBrand AS b ON p.ProductBrand = BrandID " &
 
                         "INNER JOIN tblFromulation AS f ON p.ProductFromulation = FromulationID " &
 
                         "INNER JOIN tblClassification AS c ON p.ProductClassification = ClassificationID " &
 
                         "INNER JOIN tblType AS t ON p.ProductType = TypeID " &
 
                         "WHERE ProductQuantity > 0 AND " cboFilter.Text " LIKE @SearchText"

 
   cm = New SqlCommand(querycn)
 
   cm.Parameters.AddWithValue("@SearchText""%" txtSearch.Text "%")

 
   dr cm.ExecuteReader()

 
    DataGridView
    While dr
.Read()
 
       i += 1
        total 
+= CInt(dr.Item("ProductQuantity").ToString())
 
       DataGridView1.Rows.Add(i
 
                              dr.Item("ProductID").ToString(), 
 
                              dr.Item("ProductBarcode").ToString(), 
 
                              dr.Item("GenericName").ToString(), 
 
                              dr.Item("BrandName").ToString(), 
 
                              dr.Item("FromulationName").ToString(), 
 
                              dr.Item("ClassificationName").ToString(), 
 
                              dr.Item("TypeName").ToString(), 
 
                              dr.Item("ProductQuantity").ToString(), 
 
                              dr.Item("ProductBuyPrice").ToString(), 
 
                              dr.Item("ProductSalePrice").ToString(), 
 
                              Format(CDate(dr.Item("ProductDate").ToString()), "yyyy/MM"), 
 
                              dr.Item("ProductReorder").ToString())
 
   End While

 
      dr.Close()
 
   cm Nothing
        cn
.Close()

 
     lblCount.Text "عدد المنتجات: " Format(CLng(DataGridView1.Rows.Count), "#,##0") & Space(10) & " كمية المنتجات: " Format(total"#,##0")
End Sub 

استاذنا العزيز اتعبتك معي اليوم جزيتم خيرا
خطأ واحد فقط
اضافة الى Incorrect syntax near the keyword 'LIKE'.'

الرد }}}
تم الشكر بواسطة:
#7
الصورة غير موجودة
لو ترفق مثال ليتم التعديل
[صورة مرفقة: images?q=tbn:ANd9GcT72OLJW7D1E5QW-HUeWeJ...TGoNeg2jnQ]
الرد }}}
تم الشكر بواسطة:
#8
(15-07-24, 12:28 PM)تركي الحلواني كتب : الصورة غير موجودة
لو ترفق مثال ليتم التعديل

المثال الاول هذا الفيديو المتبع للشرح





هذه الصورة
الرد }}}
تم الشكر بواسطة:
#9
الغيها

PHP كود :
Sub LoadRecords()
    Dim i As Integer = 0
    Dim total As Double 
= 0
    DataGridView1
.Rows.Clear()

    cn.Open()

        Dim query As String = "SELECT * FROM tblProduct AS p " &
                          "INNER JOIN tblGeneric AS g ON p.ProductGeneric = GenericID " &
                          "INNER JOIN tblBrand AS b ON p.ProductBrand = BrandID " &
                          "INNER JOIN tblFromulation AS f ON p.ProductFromulation = FromulationID " &
                          "INNER JOIN tblClassification AS c ON p.ProductClassification = ClassificationID " &
                          "INNER JOIN tblType AS t ON p.ProductType = TypeID " &
                          "WHERE ProductQuantity > 0 AND " & cboFilter.Text & " LIKE @SearchText"

    cm = New SqlCommand(query, cn)
    cm.Parameters.AddWithValue("@SearchText", "%" & txtSearch.Text & "%")

    dr = cm.ExecuteReader()

         While dr.Read()
        i += 1
        total 
+= CInt(dr.Item("ProductQuantity").ToString())
        DataGridView1.Rows.Add(i, 
                               dr
.Item("ProductID").ToString(), 
                               dr
.Item("ProductBarcode").ToString(), 
                               dr
.Item("GenericName").ToString(), 
                               dr
.Item("BrandName").ToString(), 
                               dr
.Item("FromulationName").ToString(), 
                               dr
.Item("ClassificationName").ToString(), 
                               dr
.Item("TypeName").ToString(), 
                               dr
.Item("ProductQuantity").ToString(), 
                               dr
.Item("ProductBuyPrice").ToString(), 
                               dr
.Item("ProductSalePrice").ToString(), 
                               Format
(CDate(dr.Item("ProductDate").ToString()), "yyyy/MM"), 
                               dr
.Item("ProductReorder").ToString())
    End While

       dr
.Close()
    cm = Nothing
        cn
.Close()

      lblCount.Text = "عدد المنتجات: " & Format(CLng(DataGridView1.Rows.Count), "#,##0") & Space(10) & " كمية المنتجات: " & Format(total, "#,##0")
End Sub  
[صورة مرفقة: images?q=tbn:ANd9GcT72OLJW7D1E5QW-HUeWeJ...TGoNeg2jnQ]
الرد }}}
تم الشكر بواسطة:
#10
(15-07-24, 02:35 PM)تركي الحلواني كتب : الغيها

PHP كود :
Sub LoadRecords()
    Dim i As Integer = 0
    Dim total As Double 
= 0
    DataGridView1
.Rows.Clear()

    cn.Open()

        Dim query As String = "SELECT * FROM tblProduct AS p " &
                          "INNER JOIN tblGeneric AS g ON p.ProductGeneric = GenericID " &
                          "INNER JOIN tblBrand AS b ON p.ProductBrand = BrandID " &
                          "INNER JOIN tblFromulation AS f ON p.ProductFromulation = FromulationID " &
                          "INNER JOIN tblClassification AS c ON p.ProductClassification = ClassificationID " &
                          "INNER JOIN tblType AS t ON p.ProductType = TypeID " &
                          "WHERE ProductQuantity > 0 AND " & cboFilter.Text & " LIKE @SearchText"

    cm = New SqlCommand(query, cn)
    cm.Parameters.AddWithValue("@SearchText", "%" & txtSearch.Text & "%")

    dr = cm.ExecuteReader()

         While dr.Read()
        i += 1
        total 
+= CInt(dr.Item("ProductQuantity").ToString())
        DataGridView1.Rows.Add(i, 
                               dr
.Item("ProductID").ToString(), 
                               dr
.Item("ProductBarcode").ToString(), 
                               dr
.Item("GenericName").ToString(), 
                               dr
.Item("BrandName").ToString(), 
                               dr
.Item("FromulationName").ToString(), 
                               dr
.Item("ClassificationName").ToString(), 
                               dr
.Item("TypeName").ToString(), 
                               dr
.Item("ProductQuantity").ToString(), 
                               dr
.Item("ProductBuyPrice").ToString(), 
                               dr
.Item("ProductSalePrice").ToString(), 
                               Format
(CDate(dr.Item("ProductDate").ToString()), "yyyy/MM"), 
                               dr
.Item("ProductReorder").ToString())
    End While

       dr
.Close()
    cm = Nothing
        cn
.Close()

      lblCount.Text = "عدد المنتجات: " & Format(CLng(DataGridView1.Rows.Count), "#,##0") & Space(10) & " كمية المنتجات: " & Format(total, "#,##0")
End Sub  

الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  ممكن ايضاح اكثر لـ continu for justforit 6 304 05-11-25, 12:10 AM
آخر رد: justforit
  [VB.NET] اذا ممكن مشروع ادارة مدرسة بدر إشتية 4 8,527 08-02-25, 02:05 AM
آخر رد: الورد2
  ارجو تعديل الكود جلب البيانات عن طريق اجراء مخزن - مرفق مثال new_programer 0 619 05-02-25, 01:51 AM
آخر رد: new_programer
  ممكن اعرف معنى مفهومي HLD ,LLD bassant 0 309 30-01-25, 02:07 PM
آخر رد: bassant
  [سؤال] اجراء المسح الضوئي وتصوير المستندات من خلال المستعرض ابوعبدالملك 3 357 24-01-25, 06:37 AM
آخر رد: ابوعبدالملك
  شيء غريب ممكن تفسير justforit 2 354 03-12-24, 11:44 PM
آخر رد: justforit
Exclamation [VB.NET] ممكن كود تشغيل ملف صوت MP3 الورد الصناعي 10 905 20-10-24, 03:08 PM
آخر رد: salamandal
Exclamation [VB.NET] ممكن عمل كود لحفظ المكتوب داخل اداة TextBox الورد الصناعي 9 776 17-10-24, 11:43 PM
آخر رد: salamandal
  ممكن طريقة عمل الصورة بشكل دائري بوحمد 3 483 14-10-24, 04:01 PM
آخر رد: بوحمد
  السلام عليكم ممكن كود بحث فى برنامج مصمم بالفيجوال بيسك وقاعدة بيانات اكسس خالد كامل1 1 451 08-10-24, 02:37 PM
آخر رد: salamandal

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم