Ado.net 介绍:Connection 对象与方法
1:ConnectionString – (属性) 获取或者设置连接语句.
2:Open – (方法) 打开当前数据库连接.
3:Close – (方法) 关闭当前连接.
4:State – (属性) 获取当前的连接状态
下面以两种数据提供器以示例说明上面的四种属性与方法:
在开始使用之前必须为不同的数据源声明命名空间:

  1. using System.Data.SqlClient; //SqlClient数据提供器
  2. using System.Data.OleDb; //OleDb数据提供器

1:SqlClient 数据提供器:应用于SQL 7 以上-共有三种代码表现形式(SQL)

  1. 方式1:
  2. SqlConnection conn = new SqlConnction("Data Source=localhost;Initial Catalog=dataname;Persist Security Info=True;User ID=sa;Password=gothic");
  3. conn.Open(); //打开数据源连接
  4. Response.Write(conn.State); //当前与数据源的状态
  5. conn.Close(); //关闭数据库连接
  6. 方式2://使用ConnectionString属性
  7. SqlConnection conn = new SqlConnction();
  8. conn.ConnectionString = "Data Source=localhost;Initial Catalog=dataname;Persist Security Info=True;User ID=sa;Password=gothic";
  9. conn.Open();
  10. conn.Close();
  11. 方式3://使用web.config定义好的数据源
  12. web.config 内节点代码表现:
  13. //注意此外的命名空间:System.Data.SqlClient
  14. -------------------------------------------
  15. SqlConnection conn = new SqlConnction();
  16. conn.ConnectionString = ConfigruationManager.ConnectionStrings["sqlconn"] .ConnectionString;
  17. conn.Open();

Read the rest of this entry »

, ,

Net之旅:Ado.net 组件介绍Connection对象-Command对象-DataReader对象-DataSet对象-DataAdapter对象

基本上使用的数据连接器分两种:
MS SQL连接方式与非MS SQL连接方式

  1. 1 : SqlClient   //数据提供者:应用于SQL 7 以上
  2. 2 : OleDb      //数据提供者应用于SQL 7 以下 或 其它数据库
  1. Connection对象:
  2. 用于数据连接,也可以说成是他与 Provider 或者 Driver 的信息通道
  3. Command对象:
  4. 用于执行针对数据源的命令和检索 DateReader 或 DataSet 或者用于执行对数据源的SQL语句
  5. DataReader对象:
  6. 一个已连接并向前的只读数据集
  7. DataSet对象:
  8. 一个保存了查询结果并与服务器断开的内存数据库
  9. DataAdapter:
  10. 用于从数据源产生的一个 DataSet 并更新数据源

, , , , , ,

Net之旅:FileUpload控件-FileUpload控件相比其它上传组件与无组件上传类在效率上都略胜一筹。FileUpload的最大上传限制为200M。
1:FileUpload控件的页面代码表现形式
描述:1个FileUpload控件 与 1个Button控件

  1. <asp :FileUpload ID="FileUpload1" runat="server" BorderStyle="Inset" />
  2. <br /> <br />
  3. <asp :Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />

2:处理上传文章数据:
描述:通过单击Button处理FileUpload控件上的文件。

  1. protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.         string name = FileUpload1.FileName;
  4.         //获取文件名称
  5.         string size = FileUpload1.PostedFile.ContentLength.ToString();
  6.         //获取文件大小
  7.         string type1 = FileUpload1.PostedFile.ContentType;
  8.         //获取文件以MIME类型
  9.         string type2 = name.Substring(name.LastIndexOf(".")+1);
  10.         //获取文件后缀
  11.         string path1 = Server.MapPath("Images") + "\\" + name;
  12.         //定义上传文章的路径
  13.         FileUpload1.SaveAs(path1); //将文件保存到ipath
  14.         //把文件保存至path1路径
  15.     }
  16. }

Read the rest of this entry »

, , ,

Net之旅:BulletedList控件
对于一些各种列表,甚至普通文字新闻列表的表现。都可以用BulletedList控件控件来实现.

1:BulletedList控件列表项目:

  1. 1:可以建立数据源从中显示出来.
  2. 2:编辑项-自主添加列表项.

2:BulletedList控件个别参数:

  1. 1:DisylayMode
  2. Text/HyperLink/LinkButton -文字/文字连接/按钮连接
  3. 2:BulletStyle
  4. //此处参数就不写了有些多、设置此参数是改变列表项开头的。1 a i 等
  5. 3:BulletImageUrl
  6. //此参数在BulletStyle参数设置为:CustomImage时才能效用来设置列表项头的图片;

Read the rest of this entry »

, , ,