文档介绍:-03
string sqls = "select count(*) from Admin where LoginId=***@lid and oginPwd=***@lpwd";
mand cmd = new mand(sqls, );
SqlParameter sp1=new SqlParameter("lid",);
=;
(sp1);
SqlParameter sp2 = new SqlParameter("lpwd", );
= ;
(sp2);
 
();
 
int i = (int)();
= ();
带参数的查询语句
P82使用数据前的准备-SQL语句
讲述T-SQL之前…
语法检查
数据库对象
执行
选择数据库
T-SQL
执行结果
查询
SELECT <列名>
FROM <表名>
[WHERE <查询条件表达式>]
[ORDER BY <排序的列名>[ASC或DESC]]
列名称
SELECT
SCode,
SName,
SAddress
表名
FROM
Students
过滤条件
WHERESSEX = 0
排序条件
ORDER BYSCode
SELECT SCode,SName,SAddress
FROM Students
WHERE SSEX = 0
ORDER BY SCode
DataReader
SqlDataReader theDataReader =
);
string outputRow = ;
if ()
{
while (())
{
outputRow =
[0].PadRight(50) + "\t" +
[1] + "\n";
(outputRow);
}
}
P85
//DataReader—实际例子
string sqls = "select * from Admin";
mand cmd = new mand(sqls, );
if ( == )
();
SqlDataReader theDataReader = );
string outputRow = ;
if ()
{
while (())
{
outputRow =(1).PadRight(50) + "\t" +
(2) + "\n";
(outputRow);
}
}
();
//多结果集P86
SqlDataReader theDataReader =
);
string outputRow = ;
if ()
{
bool hasMoreResults = true;
while (hasMoreResults)
{
while (())
{
outputRow =
[0].PadRight(50) + "\t" +
[1] + "\n";
(outputRow);
}
hasMoreResults =