打印本文 打印本文 关闭窗口 关闭窗口
在asp.net中操作sql-server数据库的一些小技巧
作者:武汉SEO闵涛  文章来源:敏韬网  点击数4302  更新时间:2007/11/14 13:06:47  文章录入:mintao  责任编辑:mintao

string s="Davolio";

 

SqlConnection thisConnection=new SqlConnection

("Data Source=(local);Initial Catalog=Northwind;UID=sa;PWD=");

thisConnection.Open ();

SqlCommand thisCommand=thisConnection.CreateCommand ();

 

thisCommand.CommandText =

" select * from employees where LastName=@charname";

thisCommand.Parameters.Add("@charname",s);

 

 

可以看到,字符串s将参数“Ddbolio”传递给数据库操作语句中的参数charname。

2.将数据库中不同表内的数据读入到数据集DataSet中

SqlDataAdapterFill方法可以填充已知数据集,并且为每个填充项创建一个临时表,可以通过对该表的访问来读取数据集中的相关数据。其相关操作如下所示:

上一页  [1] [2] [3] [4]  下一页

打印本文 打印本文 关闭窗口 关闭窗口