如何将数据表值保存到数据库 [英] how to save datatable values to database

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

问题描述

先生您好,

我有两个文本框和一个按钮.使用这些文本框,我将一些值插入到gridview中.在此过程中,我将创建数据表和数据行并填充gridview.运行正常.
我的要求是如何保存通过数据表插入数据库中的这些值.

如果有人知道,请告诉我.
谢谢.

Hello sir,

I have two textboxes and one button. With these textboxes I am inserting some values to gridview. In this process I am creating datatable and datarow and fill up the gridview. It is working perfectly.
My requirememnt is how can I save these values inserting though datatable in database.

If any body knows, please tell me.
Thank you.

推荐答案

[
This[^] may help.


您可以使用给定的命令格式使用以下命令保存数据数据表.

you can use given Command Format to save your Data using Datatable.

SqlCommand cmd = new SqlCommand("Command ", Connection);
      SqlDataAdapter da = new SqlDataAdapter();
      da.SelectCommand = cmd;
      SqlCommandBuilder cmdbuilder = new SqlCommandBuilder(da);
      DataSet ds = new DataSet();
      da.Fill(ds, "TableName");
      DataTable dt = ds.Tables["TableName"];
      DataRow  dr = dt.NewRow();
      dr[index] = textbox1.Text;
      dr[index] = textbox2.Text;
      dt.Rows.Add(dr);
       da.Update(ds, "TableName"); // Saves Data


这篇关于如何将数据表值保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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