C# SQLAdapter.Update不起作用
我对SQLAdapter.Update()有问题,它不起作用C# SQLAdapter.Update不起作用,c#,sql,wpf,C#,Sql,Wpf,我对SQLAdapter.Update()有问题,它不起作用 table = new DataTable(); mycommand = "select * from klient"; command = new SqlCommand(); command.CommandText = mycommand; command.Connection = connection; adapter = new Sq
table = new DataTable();
mycommand = "select * from klient";
command = new SqlCommand();
command.CommandText = mycommand;
command.Connection = connection;
adapter = new SqlDataAdapter(command);
adapter.Fill(table);
data.ItemsSource = table.DefaultView;
(数据是DataGrid的名称)
当我尝试更新时,它会在数据库中产生效果,但不会在datagrid中产生效果
mycommand= "update klient set imie = 'ze'";
command.CommandText = mycommand;
adapter = new SqlDataAdapter();
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
adapter.UpdateCommand = command;
adapter.UpdateCommand.ExecuteNonQuery();
adapter.Update(table);
最后一行不行。有谁能帮我解决这个问题吗
adapter.UpdateCommand = command;
adapter.UpdateCommand.ExecuteNonQuery();
adapter.Update(table);
data.ItemsSource = table.DefaultView;
仍然不起作用,我提出了一些解决方案,但它们并不完全符合我想要的
table.Clear();
adapter.SelectCommand = command;
adapter.SelectCommand.ExecuteNonQuery();
adapter.Fill(table);
最后一个是解决此问题的正确方法,但它没有使用adapter.update()您所说的不工作是什么意思?它是否抛出了任何异常,或者只是没有刷新网格的视图?没有刷新,这意味着有人可以帮助我吗?