当Checkbox列为true时,保存Datagridview中的所有行

时间:2016-09-22 04:14:37

标签: vb.net datagridview datagridviewcheckboxcell

早上好 我有一个看起来像这样的程序。

Form Design

我有一个名为SaveCheckedRecords()的按钮,当我点击该按钮时会调用 Public Sub SaveCheckedRecords() Dim failed = False For Each row As DataGridViewRow In DataGridView1.Rows If row.Cells(0).Value = True Then Dim i As Integer i = DataGridView1.CurrentRow.Index Label2.Text = DataGridView1.Item("ItemCode", i).Value Label3.Text = DataGridView1.Item("Description", i).Value Label4.Text = DataGridView1.Item("ReflectedQty", i).Value Label5.Text = DataGridView1.Item("UOM", i).Value Label6.Text = DataGridView1.Item("UnitPrice", i).Value Label7.Text = DataGridView1.Item("Total", i).Value Label8.Text = DataGridView1.Item("Remarks", i).Value standard() '<------------- Call this Sub insert() '<------------- Call this Sub failed = True Exit For End If Next If Not failed Then MsgBox("Please select an item to receive") End If End Sub ,这里是代码

Subs

现在我基于上面代码的目标是将数据从datagridview行传输到标签并调用一些standard

以下是insertPrivate Sub standard() Dim con As MySqlConnection = New MySqlConnection("server=localhost;userid=root;password=admin1950;database=inventory") Dim cmd As MySqlCommand = New MySqlCommand("select StandardUOM,QtyPerUoM from item_master_list where ItemCode = '" & Label2.Text & "'", con) Dim reader As MySqlDataReader con.Open() reader = cmd.ExecuteReader While reader.Read Label9.Text = reader.GetString("StandardUOM") Label10.Text = reader.GetString("QtyPerUoM") End While End Sub Private Sub insert() DataGridView1.Columns.RemoveAt(0) Dim con1 As MySqlConnection = New MySqlConnection("datasource=localhost;database=inventory;userid=root;password=admin1950") Dim cmdinsert As MySqlCommand = New MySqlCommand("insert into receiving (RINo,PONo,ItemCode,Description,QtyPack,PackUoM,UnitPrice,Total,Remarks,ExpiryDate,QtyStan,StanUoM,PCS) values ('" & frm_Add_Receiving_Items.TextBox1.Text & "','" & Label1.Text & "','" & Label2.Text & "','" & Label3.Text & "','" & Label11.Text & "','" & Label5.Text & "','" & Label6.Text & "','" & Label7.Text & "','" & Label8.Text & "','" & DateTime.Now.ToString("yyyy-MM-dd") & "','" & Label12.Text & "','" & Label9.Text & "','" & Label10.Text & "')", con1) con1.Open() cmdinsert.ExecuteNonQuery() con1.Close() frm_Add_Receiving_Items.generate_rec_form() updateRI() loadlist1() frm_Add_Receiving_Items.Button6.Enabled = False Label2.Text = "Label2" End Sub

的代码
checkboxcolumn(0)

我想要做的就是在$this->db->select("a.user_id as id, a.plate_number as plate_number, a.current_lat as lat, a.current_lon as lon, a.created_on as created_on, a.updated_on as updated_on, a.available as available, a.location_id as location_id, b.user_name as name, b.user_email as email, b.user_phone as phone, c.name as location_name"); $this->db->from('user_driver as a'); $this->db->join('user as b', 'a.user_id = b.user_id'); $this->db->join('vendor_location as c', 'a.location_id = c.location_id'); $query = $this->db->get(); $data['driver'] = $query->result_array(); 为True时保存datagridview的值我的代码是否错误?

TYSM

0 个答案:

没有答案