你把SDK装好,里面就有很多例子:)
解决方案 »
- 关于SQL的distinct 和order by 问题
- 使用 GridView 自带的查找 更新 删除 方法
- 关于文档流
- vs2008怎么没有像2005一样的插入层?而且即使手动添加<div>......</div>也不能随意拖动......
- excel导入SQL 如何结束EXCEL进程
- 怎么能防止游客下载网站上的图片。
- 文件操作类,应该放到哪一层?
- 有很多论坛都可以很醒目的显示新帖子 是根据什么做的点击率还是时间?怎么和数据库联系起来 请高手指点一下 最好有源代码 谢谢
- TreeView (vb asp.net VS2003) 连接数据库如何使用?
- 用存储过程存储text型字段的问题?
- 菜鸟之结贴之王:我使用datagrid按钮列的编辑,更新,取消,第一页很正常,我点分页的第二页,再点编辑按钮,它跑到第一页去了。谁遇到过
- 有关DataGrid和Image绑定的问题
Walkthrough: Editing an Access Database with ADO.NET
http://www.microsoft.com/indonesia/msdn/adon_wtaccessdb.asp
http://download.microsoft.com/download/c/b/9/cb93399c-2ecd-4d31-bde6-82bd74f4c79b/ADONETAccessDB.exe
private void CreateDataAccess(){
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=SX;packet size=4096;user id=sa;data source=dbserver;persist security" +
" info=False;initial catalog=dbname";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "ECOM_FeeDetail", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("ID", "ID"),
new System.Data.Common.DataColumnMapping("OBR_PKID", "OBR_PKID"),
new System.Data.Common.DataColumnMapping("FeeType_PKID", "FeeType_PKID"),
new System.Data.Common.DataColumnMapping("FeeNumber", "FeeNumber")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT ID, OBR_PKID, FeeType_PKID, FeeNumber FROM FeeDetail";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO FeeDetail(OBR_PKID, FeeType_PKID, FeeNumber) VALUES (@OBR_PKID, " +
"@FeeType_PKID, @FeeNumber); SELECT ID, OBR_PKID, FeeType_PKID, FeeNumber FROM " +
"FeeDetail WHERE (ID = @@IDENTITY)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@OBR_PKID", System.Data.SqlDbType.Int, 4, "OBR_PKID"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FeeType_PKID", System.Data.SqlDbType.Int, 4, "FeeType_PKID"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FeeNumber", System.Data.SqlDbType.Money, 8, "FeeNumber"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE FeeDetail SET OBR_PKID = @OBR_PKID, FeeType_PKID = @FeeType_PKID, FeeNumber = @FeeNumber WHERE (ID = @Original_ID) AND (FeeNumber = @Original_FeeNumber OR @Original_FeeNumber IS NULL AND FeeNumber IS NULL) AND (FeeType_PKID = @Original_FeeType_PKID) AND (OBR_PKID = @Original_OBR_PKID); SELECT ID, OBR_PKID, FeeType_PKID, FeeNumber FROM FeeDetail WHERE (ID = @ID)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@OBR_PKID", System.Data.SqlDbType.Int, 4, "OBR_PKID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FeeType_PKID", System.Data.SqlDbType.Int, 4, "FeeType_PKID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FeeNumber", System.Data.SqlDbType.Money, 8, "FeeNumber"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FeeNumber", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FeeNumber", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FeeType_PKID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FeeType_PKID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_OBR_PKID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "OBR_PKID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ID", System.Data.SqlDbType.Int, 4, "ID"));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM FeeDetail WHERE (ID = @Original_ID) AND (FeeNumber = @Original_F" +
"eeNumber OR @Original_FeeNumber IS NULL AND FeeNumber IS NULL) AND (FeeType_PKID" +
" = @Original_FeeType_PKID) AND (OBR_PKID = @Original_OBR_PKID)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FeeNumber", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FeeNumber", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FeeType_PKID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FeeType_PKID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_OBR_PKID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "OBR_PKID", System.Data.DataRowVersion.Original, null));
}//将数据与DataGrid绑定
public void BindData()
{
this.dataSet1 = new DataSet();
this.sqlDataAdapter1.Fill(dataSet1);
this.dataGrid1.SetDataBinding(dataSet1);
}//向数据库提交数据
public void Post()
{
this.sqlDataAdapter1.Update(this.dataSet1);
}
TextBox[] arrText=new TextBox[1];
arrText[0]=(TextBox)e.Item.Cells[1].Controls[0];//编辑状态下的第一个文本框
string UptTxt = arrText[0].Text.Trim(); //取得第一个文本框中的值
下面就可以调用方法来修改数据
datalist控件
里面很详细,你看看