我有一个dataGridView,当我点击任何行打开一个表格来更新行数据,但在结束更新后,更新表格被关闭,但dataGridView数据没有更新
我怎样才能做到这一点 ?
将数据输入所有文本框后,单击提交按钮后,它不会立即显示在datagridview中,我需要重新打开表单才能看到新插入的行.要刷新什么代码?
跟着@ user3222297代码.通过添加grdPatient.Update(); 和grdPatient.Refresh(); 单击确定插入成功后仍然无法刷新.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace GRP_02_03_SACP
{
public partial class patient : Form
{
// Data Table to store employee data
DataTable Patient = new DataTable();
// Keeps track of which row in Gridview
// is selected
DataGridViewRow currentRow = null;
SqlDataAdapter PatientAdapter;
public patient()
{
InitializeComponent();
}
private void btnSubmit_Click(object sender, EventArgs e)
{
if (btnSubmit.Text == "Clear") …Run Code Online (Sandbox Code Playgroud) 有人得到了解释发生了什么?将代码1更改为代码2可以解决问题 - 尽管理论上应该没有区别.(理论打击练习就像南瓜击中砖墙).
代码1:
OutputDataGridView.DataSource = myList;
Run Code Online (Sandbox Code Playgroud)
代码2:
OutputDataGridView.DataSource = null;
OutputDataGridView.DataSource = myList;
Run Code Online (Sandbox Code Playgroud) 如何在从另一个表单对数据库进行更改后刷新datagridview,关闭子表单后我试图用click事件刷新datagridview但是它不起作用,我是否必须使用数据集?
//create an OleDbDataAdapter to execute the query
dAdapter = new OleDbDataAdapter(gQuery, connString);
//create a command builder
cBuilder = new OleDbCommandBuilder(dAdapter);
//create a DataTable to hold the query results
dTable = new DataTable();
//fill the DataTable
dAdapter.Fill(dTable);
//BindingSource to sync DataTable and DataGridView
bSource = new BindingSource();
//set the BindingSource DataSource
bSource.DataSource = dTable;
//set the DataGridView DataSource
dataGridView1.DataSource = bSource;
private void button_Refresh_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = bSource;
dataGridView1.Refresh();
}
Run Code Online (Sandbox Code Playgroud)
请帮帮我,请提前谢谢
我有一个datagridview.我读了一个xml文件并将数据绑定到gridview.我更改了xml并以另一种形式保存.所以我重读了xml文件并将其绑定到gridview.数据表正在获取更新的值.但是在我关闭并再次打开应用程序之前,网格没有得到更新.怎么做?
谢谢.
此致,Raghavendra
#1
DataGridView是否有Databind()或Rebind()?我像这样设置数据源 -
dvMoviesList.DataSource = dtMovies;
Run Code Online (Sandbox Code Playgroud)
如果我将任何新行添加到dtMovies表并再次设置数据源,它将被反映出来.但是,如果我编辑任何现有行的值并重新分配数据源,则在我关闭并再次打开应用程序之前,它不会被反映出来.有任何想法吗?
谢谢.
我正在更新表格中的一行.表的一个子集显示在DataGridView中.当我更新行时,更改不会反映在DataGridView中.即使我在提交更改后调用DataGridView.Invalidate()和DataGridView.Refresh(),我也必须关闭应用程序,重新启动并重新运行查询,然后才能看到更改.
相关代码是:
private void buttonUpdate_Click(object sender, EventArgs e)
{
const int TICKETID_COLUMN = 0;
String _ticketID = dataGridView1.CurrentRow.Cells[SOME_COLUMN].Value.ToString();
UpdateRecord(_ticketID, textBoxTicketSource.Text,
textBoxAboutSomeID.Text, textBoxCategoryID.Text, textBoxContactEmail.Text);
}
private void UpdateRecord(string ATicketID, string ATicketSource, string
AAboutSomeID, string ACategoryID, string AContactID)
{
oracleConnection1.Open();
OracleCommand ocmd = new OracleCommand();
OracleTransaction ot;
// Start a local transaction
ot = oracleConnection1.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
// Assign transaction object for a pending local transaction
ocmd.Transaction = ot;
ocmd.Connection = oracleConnection1;
try
{
ocmd.CommandText = @"UPDATE ABC.CONCERTTICKETS
SET TICKETSOURCE = :p_TICKETSOURCE,
ABOUTSOMEID = …Run Code Online (Sandbox Code Playgroud) datagridview ×6
c# ×5
.net ×1
button ×1
dataadapter ×1
dataset ×1
dotconnect ×1
insert ×1
oracle ×1
refresh ×1
winforms ×1