ممكن المساعدة في اجراء بحث كومبوبكس وتيكست - raedre22 - 15-07-24
السلام عليكم ورحمة الله وبركاته :-
الاساتذة الاعزاء انا جديد في عالم البرمجة لذا اتبع شروحات لتكوين برنامج
في احد الاجرائات المستخدمة يكون الشرح على بأستخدام 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]
RE: ممكن المساعدة في اجراء بحث كومبوبكس وتيكست - تركي الحلواني - 15-07-24
جرب هذا
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
RE: ممكن المساعدة في اجراء بحث كومبوبكس وتيكست - raedre22 - 15-07-24
(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
شكرا جزيلا سوف اجرب ان شاء الله
RE: ممكن المساعدة في اجراء بحث كومبوبكس وتيكست - raedre22 - 15-07-24
(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
RE: ممكن المساعدة في اجراء بحث كومبوبكس وتيكست - تركي الحلواني - 15-07-24
جرب هذا
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
RE: ممكن المساعدة في اجراء بحث كومبوبكس وتيكست - raedre22 - 15-07-24
(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'.'
RE: ممكن المساعدة في اجراء بحث كومبوبكس وتيكست - تركي الحلواني - 15-07-24
الصورة غير موجودة
لو ترفق مثال ليتم التعديل
RE: ممكن المساعدة في اجراء بحث كومبوبكس وتيكست - raedre22 - 15-07-24
(15-07-24, 12:28 PM)تركي الحلواني كتب : الصورة غير موجودة
لو ترفق مثال ليتم التعديل
المثال الاول هذا الفيديو المتبع للشرح
هذه الصورة
RE: ممكن المساعدة في اجراء بحث كومبوبكس وتيكست - تركي الحلواني - 15-07-24
الغيها
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
RE: ممكن المساعدة في اجراء بحث كومبوبكس وتيكست - raedre22 - 15-07-24
(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
|