将TextBox数据提交到GridView显示(DataTable的应用2)
来源:互联网 发布:cf辅助瞄准软件 编辑:程序博客网 时间:2024/05/20 08:44
这个栗子的分析请回头看前面那章节的分析:关于DataTable如何取值
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class DataSet_InsertData : System.Web.UI.Page
{
private string strConn = "data source=localhost;initial catalog=Northwind;user id=sa;password=sa";
SqlConnection Conn;
SqlDataAdapter myDataAdapter;
DataSet myDataSet;
protected void Page_Load(object sender, EventArgs e)
{
Conn = new SqlConnection(strConn);
string strSql = "SELECT * FROM Categories";
myDataAdapter = new SqlDataAdapter(strSql, Conn);
//创建CommandBuilder对象,该对象可以自动创建用于插入、删除及更新的SQL语句
SqlCommandBuilder myCB = new SqlCommandBuilder(myDataAdapter);
if (!IsPostBack)
{
//调用FillGridView()方法,用以显示数据
FillGridView();
}
}
private void FillGridView()
{
myDataSet = new DataSet();
Conn.Open();
myDataAdapter.Fill(myDataSet, "Categories");
Conn.Close();
myGridView.DataSource = myDataSet.Tables["Categories"];
myGridView.DataBind();
}
protected void OK_Click(object sender, EventArgs e)
{
DataSet InsertDataSet = new DataSet();
Conn.Open();
myDataAdapter.Fill(InsertDataSet, "Categories");
Conn.Close();
//创建一个新行,准备添加新的数据
DataRow insertRow = InsertDataSet.Tables["Categories"].NewRow();
//指定新行中每一个字段的值
insertRow["CategoryName"] = txtCategoryName.Text;
insertRow["Description"] = txtDescription.Text;
//将创建并填充数据的行insertRow添加到InsertDataSet中的Categories表格中
InsertDataSet.Tables["Categories"].Rows.Add(insertRow);
//使用DataAdapter对象的Update方法更新插入新行后的数据表Categories
myDataAdapter.Update(InsertDataSet.Tables["Categories"]);
txtCategoryName.Text = "";
txtDescription.Text = "";
//调用FillGridView()方法,重新显示插入新行后的数据信息
FillGridView();
}
}
- 将TextBox数据提交到GridView显示(DataTable的应用2)
- 如何将TextBox数据提交到GridView显示再保存到数据库
- ASP.NET中通过GRIDVIEW"选择"的按钮将数据显示到TEXTBOX中
- dataGridView将数据显示到textBox
- 将GridView的数据生成DataTable
- 将GridView数据放入DataTable
- 从TextBox添加到DataTable填充到GridView中显示之【此过程同时检测某个字段时候已经存在】
- 将GridView数据转入datatable,并将数据保存到固定路径
- 将 GridView、DataTable,DataSet 中的内容导出到 Excel 中多个工作表(Sheet) 的方法
- jQuery-datatable添加和修改提交到服务器的数据
- 将gridview中的数据行绑定到上面的输入框里显示
- 将DataGrid(gridview)中的数据赋值到datatable,只需要一句
- 单击GridView的TextBox,显示Calendar
- NPOI,将Excel表的数据存放到DataTable中
- 将DataTable的数据保存到XML中
- winform 中如何将查询出的数据(DataSet或DataTable)显示在reportViewer?
- 如何将回车提交表单事件绑定到textbox控件?
- 绑定数据显示到 GridView
- ubuntu上SVN版本升级到1.7
- SDUTOJ 1299 最长上升子序列
- Oracle DB对数据进行限制和排序
- java cmd编译后运行是区分大小写的
- 堆排序的应用 Priority queues 优先级排序
- 将TextBox数据提交到GridView显示(DataTable的应用2)
- Linux下批量修改文件及文件夹所有者及权限
- 电脑开机各种提示音
- apt-get remove删除的内容 dpkg -l还是能看到
- c++基础知识
- 不懂?求助
- 利用集成 windows身份验证在 IIS中承载此服务,以保护服务器
- mysql查询操作及正则表达式小结
- Mysql数据库从本地导出、服务器上导入时报:ERROR 2005 (HY000): Unknown MySQL server host 'mysql' 的一种解决方案