求解这两道题

来源:百度知道 编辑:UC知道 时间:2024/05/31 19:11:24
1、Spot the mistakes in C# or write the following in C++ .Also take care of memory leaks. Just highlight and state the mistakes within the space provided.

Private static string m_dsn = “data source = xxx, 1433; Network Library=dbmsscon; Initial Catalog=xx; Password=xxx”;

Public static sqlconnection Getconnection () {
Sqlconnection conn = new Sqlconnection (m_dsn):
conn.open ();
Return conn;
}

Public static count records () {
Try
{
Din count =0;
Sqlconnection myconnection = Getconnection ();
Sqlcommand mySQL=new Sqlcommand (“Select * from visitor where groupID=” *grpid* “;”, myconnection);
Sqldatareader mReader= mySQL.ExecuteReader ();
While { mReader.Read () }
count=count + 1;

Return count;
}
}

把这个语句:
Select * from visitor where groupID=" *grpid* "
改成
Select count(0) from visitor where groupID=" *grpid* "

2. There

看懂了一些,似乎说编写更加简答与更加高效的SQL语句,
呵呵,提问的时候最好自己也对问题进行分析一下,
这样将问题突出,便于大家回答,
呵呵,希望能有帮助,^_^

Sqlcommand mySQL=new Sqlcommand (“Select * from visitor where groupID=” *grpid* “;”, myconnection);
Sqldatareader mReader= mySQL.ExecuteReader ();
While { mReader.Read () }
count=count + 1;
换成
Sqlcommand mySQL=new Sqlcommand (“Select count(0) from visitor where groupID=" *grpid* ";”, myconnection);
count=mySQL.ExecuteScalar(); //这里可能要转换一下.我只会c#所以c++的转换函数我不知道..你自己把他转成int
return count

这好象C#.net的,我不知道你到底想问什么?只写代码不说问什么怎么回答。

它认识我,我不认识它