设为首页 加入收藏

TOP

在vs.net bate 2中的ado.net简单编程(傻瓜版)(一)
2014-11-23 20:25:17 来源: 作者: 【 】 浏览:13
Tags:vs.net bate ado.net 简单 编程 傻瓜
这篇文章只适合初学者,如果你是大虾,这篇文章就是浪费你的时间。

首先,文件->兴建->项目。项目类型:C#,ASP。NET应用程序。

在工具箱中拖一个sqldataadapter到webform窗口中。

向导先点下一步,新建连接,在连接标签下,选取一个可用的服务器和可用的sqlserver数据库,确定。

然后配置查询生成器(太简单就不说了)。完成。

在webform中点击sqldataadapter1在属性栏的下面点生成数据集。单选框用新建,确定。

至此,和数据库的连接工作基本搞定了,让我们来操作它吧。

拖一个datagrid到webform 窗口。属性生成器中选好数据源(我们只有一个dataset)也就这样了。

然后我们来看看代码。

切换到代码窗口,添加黄色的代码:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
///


/// Summary description for WebForm1.
///

public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter2;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand2;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand2;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection2;
protected System.Web.UI.WebControls.DataGrid DataGrid2;
protected WebApplication1.DataSet1 dataSet11;

public WebForm1()
{
Page.Init += new System.EventHandler(Page_Init);
}

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

private void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
//填充数据集

sqlDataAdapter1.Fill (dataSet11);

//绑定
DataGrid1.DataBind ();

} #region Web Form Designer generated code
///


/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()

#endregion

}

生成程序,如果正常的话你应该可以在datagrid看到你的数据了。

如果你对操作的数据有更高的要求的话(前提是会sql语句),你可以点饥前面绿色代码前的小加号,修改下面的兰色代码。
private void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.dataSet11 = new WebApplication1.DataSet1();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDataAdapter2 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection2 = new System.Data.SqlClient.SqlConnection();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.Button1.

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Blackcomb 和Windows.NET 现身? 下一篇在 Windows 2000 中如何配置 IPSe..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: