OleDbCommand cmd = new OleDbCommand("select i.billno,i.idate,i.cname,i.address,i.mob,p.brand_name,p.category,p.price,i.quantity,p.gstper_product,i.sub_total,t.grand_total from (customer_invoice_details i inner join product p on i.pid=p.pid) inner join totalamt t on i.billno=t.billno where i.idate between @date1 and @date2", con);
cmd.Parameters.AddWithValue("@date1", dateTime1.Value.ToString());
cmd.Parameters.AddWithValue("@date2", datetimeto.Value.ToString());
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
所以请帮我怎么做...
答案 0 :(得分:0)
我有类似的问题。为了更新datagrid,我使用了刷新方法。
dataGridView1.Refresh();
还有一次它通过重置数据绑定到数据网格对我有用
dataGridView1.DataSource = null;
dataGridView1.DataSource = dt;
答案 1 :(得分:0)
您将如何更新上面提到的记录。 正在为您提供一个示例尝试。
从DataGridView中将选定的行值获取到文本框中
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
' get the index of the selected datagridview row
index = e.RowIndex
Dim selectedRow As DataGridViewRow
' show data from the selected row to textboxes
selectedRow = DataGridView1.Rows(index)
TextBoxID.Text = selectedRow.Cells(0).Value.ToString()
TextBoxFN.Text = selectedRow.Cells(1).Value.ToString()
TextBoxLN.Text = selectedRow.Cells(2).Value.ToString()
TextBoxAGE.Text = selectedRow.Cells(3).Value.ToString()
End Sub
使用文本框更新datagridview所选行
Private Sub btn_Update_Click(ByVal sender As Object, ByVal e As EventArgs)
If txt_Name.Text <> "" AndAlso txt_State.Text <> "" Then
cmd = New SqlCommand("update tbl_Record set Name=@name,State=@state where ID=@id", con)
con.Open()
cmd.Parameters.AddWithValue("@id", ID)
cmd.Parameters.AddWithValue("@name", txt_Name.Text)
cmd.Parameters.AddWithValue("@state", txt_State.Text)
cmd.ExecuteNonQuery()
MessageBox.Show("Record Updated Successfully")
con.Close()
DisplayData()
ClearData()
Else
MessageBox.Show("Please Select Record to Update")
End If
End Sub