المشاركات : 19
المواضيع 4
الإنتساب : Mar 2024
السمعة :
0
الشكر: 0
تم شكره 0 مرات في 0 مشاركات
السلام عليكم ورحمة الله وبركاته :-
الاساتذة الاعزاء انا جديد في عالم البرمجة لذا اتبع شروحات لتكوين برنامج
في احد الاجرائات المستخدمة يكون الشرح على بأستخدام 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]
المشاركات : 521
المواضيع 2
الإنتساب : Sep 2013
السمعة :
25
الشكر: 93
تم شكره 525 مرات في 235 مشاركات
جرب هذا
PHP كود :
cn.Open() Dim filterColumn As String = cboFilter.Text Dim searchText As String = txtSearch.Text
Dim validColumns As New List(Of String) From {"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
المشاركات : 19
المواضيع 4
الإنتساب : Mar 2024
السمعة :
0
الشكر: 0
تم شكره 0 مرات في 0 مشاركات
(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 String) From {"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
شكرا جزيلا سوف اجرب ان شاء الله
المشاركات : 19
المواضيع 4
الإنتساب : Mar 2024
السمعة :
0
الشكر: 0
تم شكره 0 مرات في 0 مشاركات
(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 String) From {"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
المشاركات : 521
المواضيع 2
الإنتساب : Sep 2013
السمعة :
25
الشكر: 93
تم شكره 525 مرات في 235 مشاركات
جرب هذا
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()
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
المشاركات : 19
المواضيع 4
الإنتساب : Mar 2024
السمعة :
0
الشكر: 0
تم شكره 0 مرات في 0 مشاركات
15-07-24, 12:24 PM
(آخر تعديل لهذه المشاركة : 15-07-24, 12:28 PM {2} بواسطة raedre22.
تعديل السبب: تحديث
)
(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(query, cn) 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'.'
المشاركات : 521
المواضيع 2
الإنتساب : Sep 2013
السمعة :
25
الشكر: 93
تم شكره 525 مرات في 235 مشاركات
الصورة غير موجودة
لو ترفق مثال ليتم التعديل
المشاركات : 19
المواضيع 4
الإنتساب : Mar 2024
السمعة :
0
الشكر: 0
تم شكره 0 مرات في 0 مشاركات
(15-07-24, 12:28 PM)تركي الحلواني كتب : الصورة غير موجودة
لو ترفق مثال ليتم التعديل
المثال الاول هذا الفيديو المتبع للشرح
هذه الصورة
المشاركات : 521
المواضيع 2
الإنتساب : Sep 2013
السمعة :
25
الشكر: 93
تم شكره 525 مرات في 235 مشاركات
الغيها
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
المشاركات : 19
المواضيع 4
الإنتساب : Mar 2024
السمعة :
0
الشكر: 0
تم شكره 0 مرات في 0 مشاركات
(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
|