面对从datagridview将数据保存到oracle的问题 [英] Facing problem in saving data to oracle from the datagridview

查看:58
本文介绍了面对从datagridview将数据保存到oracle的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Windows应用的新手。

我正在尝试更新数据库中的表并成功。

但是我没有得到如何在DG中向DB添加新添加的行。



在我的代码中,我点击了一个按钮,我正在更新数据库中的表格。以下是代码。

I am new to windows app.
I am trying to update table in DB and successful in that.
But i am not getting how to insert new added rows in DGV to DB.

In my code i have a button on click of that i am updating table in DB. following is the code.

private void btnUpdate_Click(object sender, EventArgs e)
{
    Update();
}






and

private void Update()
{
    try
    {      
        adapter.Update(userTable);  // here i am able to update. But i needed a code that it also catch newly added rows and insert them in DB
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
    finally
    {
        conn.Close();
    }
}



请建议我的方式。帮助我使用代码在Windows应用程序中插入和更新Oracle DB中的数据。谢谢..


Please suggest me the way. help me with code to insert and update data in Oracle DB from windows app. Thank you..

推荐答案

嗨大师,(虽然听起来不对)



什么时候实现删除,插入和更新操作,您必须具有DataAdapter并定义其删除,插入和更新命令。您可以对数据源使用此适配器并调用适配器的更新方法。这是实现这类操作的最快捷,最简单的方法。

Hi master, (that doesn't sound right though)

When you implement Delete, Insert and Update operations you must have a DataAdapter and define its Delete, Insert and Update commands. You could use this adapter against your datasource and call the adapters' update method. That is the quickest and easiest way to implement these kind of operations.
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM table1", conn);
 adapter.InsertCommand = new SqlCommand("INSERT INTO table1 VALUES(@param1, @param2)", conn);
 adapter.InsertCommand.Parameters.Add("@param1",...);



只需对Update和Delete命令执行相同的操作。然后,创建一个DataSet并使用适配器填充它并将其作为数据网格的数据源...


Just do the same to the Update and Delete commands. Then, Create a DataSet and Fill it using the adapter and make it as a datasource of your datagrid...

DataSet ds = new DataSet();
 adapter.Fill(ds);
 DataGrid1.DataSource = ds;



如果要将更改发送到数据库,可以调用adapter.update方法...


When you want to send your changes to the database you can just call the adapter.update method...

adapter.Update(ds);



一篇很好的文章详细解释了这个:



http://www.codeguru.com/csharp/.net/net_data/datagrid/article.php/c13041



希望这有帮助。


A nice article explaining this in detail :

http://www.codeguru.com/csharp/.net/net_data/datagrid/article.php/c13041

Hope this helps.


这篇关于面对从datagridview将数据保存到oracle的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆