أتوفر على حقل TextBox وDataGridView على تطبيق بلغة Vb.net، حيث بعد إدخال قيمة في حقل النص والضغط على زر، أريد أن تضاف القيمة المُدخلة إلى جدول datagridview، وهذه هي شيفرة التطبيق:
Public Class frm_customer_orderproduct
Dim current_id As String
Private Sub frm_customer_orderproduct_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Dim regDate As Date = Date.Today()
lbl_user.Text = "Hi, " & custName & "!"
refresh_grid()
get_current_id()
End Sub
Private Sub refresh_grid()
Dim mysql As String = "SELECT FLD_PRODUCT_ID, FLD_PRODUCT_NAME, FLD_PRODUCT_PRICE FROM TBL_PRODUCTS"
Dim mydatatable As New DataTable
Dim myreader As New OleDb.OleDbDataAdapter(mysql, myconnection)
myreader.Fill(mydatatable)
grd_product.DataSource = mydatatable
End Sub
Private Sub clear_fields()
txt_id.Text = ""
txt_name.Text = ""
txt_price.Text = ""
txt_qty.Text = ""
End Sub
Private Sub get_current_id()
Dim current_row As Integer = grd_product.CurrentRow.Index
current_id = grd_product(0, current_row).Value
txt_id.Text = current_id
txt_name.Text = grd_product(1, current_row).Value
txt_price.Text = grd_product(2, current_row).Value
End Sub
Private Sub grd_product_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grd_product.CellClick
get_current_id()
End Sub
Private Sub btn_add_Click(sender As System.Object, e As System.EventArgs) Handles btn_add.Click
If txt_qty.Text = "" Then
MsgBox("Please insert quantity")
Else
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add("Product ID")
dt.Columns.Add("Product Name")
dt.Columns.Add("Price")
dt.Columns.Add("Quantity")
dr = dt.NewRow
dr("id") = txt_id.Text
dr("name") = txt_name.Text
dr("price") = txt_price.Text
dr("qty") = txt_qty.Text
dt.Rows.Add(dr)
grd_order.DataSource = dt
End If
End Sub
End Class
السؤال
سعاد
أتوفر على حقل TextBox وDataGridView على تطبيق بلغة Vb.net، حيث بعد إدخال قيمة في حقل النص والضغط على زر، أريد أن تضاف القيمة المُدخلة إلى جدول datagridview، وهذه هي شيفرة التطبيق:
Public Class frm_customer_orderproduct Dim current_id As String Private Sub frm_customer_orderproduct_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'Dim regDate As Date = Date.Today() lbl_user.Text = "Hi, " & custName & "!" refresh_grid() get_current_id() End Sub Private Sub refresh_grid() Dim mysql As String = "SELECT FLD_PRODUCT_ID, FLD_PRODUCT_NAME, FLD_PRODUCT_PRICE FROM TBL_PRODUCTS" Dim mydatatable As New DataTable Dim myreader As New OleDb.OleDbDataAdapter(mysql, myconnection) myreader.Fill(mydatatable) grd_product.DataSource = mydatatable End Sub Private Sub clear_fields() txt_id.Text = "" txt_name.Text = "" txt_price.Text = "" txt_qty.Text = "" End Sub Private Sub get_current_id() Dim current_row As Integer = grd_product.CurrentRow.Index current_id = grd_product(0, current_row).Value txt_id.Text = current_id txt_name.Text = grd_product(1, current_row).Value txt_price.Text = grd_product(2, current_row).Value End Sub Private Sub grd_product_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grd_product.CellClick get_current_id() End Sub Private Sub btn_add_Click(sender As System.Object, e As System.EventArgs) Handles btn_add.Click If txt_qty.Text = "" Then MsgBox("Please insert quantity") Else Dim dt As New DataTable Dim dr As DataRow dt.Columns.Add("Product ID") dt.Columns.Add("Product Name") dt.Columns.Add("Price") dt.Columns.Add("Quantity") dr = dt.NewRow dr("id") = txt_id.Text dr("name") = txt_name.Text dr("price") = txt_price.Text dr("qty") = txt_qty.Text dt.Rows.Add(dr) grd_order.DataSource = dt End If End Sub End Classلكن أحصل على خطأ مبيّن في الصورة التالية:
ما نوع المُشكل المصادف؟ وكيف أحلّه؟
تم التعديل في بواسطة سعاد1 جواب على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.