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中
SqlDataAdapter的Fill方法可以填充已知数据集,并且为每个填充项创建一个临时表,可以通过对该表的访问来读取数据集中的相关数据。其相关操作如下所示:
上一页 [1] [2] [3] [4] 下一页
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18