请问每句代码的意思是什么?public SqlDataReader GetmySend(string username){SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["MySQLConn"]);string cmdText = "SELECT * FROM send where name='"+username+"' ORDER BY
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 10:09:51
请问每句代码的意思是什么?public SqlDataReader GetmySend(string username){SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["MySQLConn"]);string cmdText = "SELECT * FROM send where name='"+username+"' ORDER BY
请问每句代码的意思是什么?
public SqlDataReader GetmySend(string username)
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["MySQLConn"]);
string cmdText = "SELECT * FROM send where name='"+username+"' ORDER BY id DESC";
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
SqlDataReader dr = null;
try
{
myConnection.Open();
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException ex)
{
throw new Exception(ex.Message,ex);
}
return dr;
}
请问每句代码的意思是什么?public SqlDataReader GetmySend(string username){SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["MySQLConn"]);string cmdText = "SELECT * FROM send where name='"+username+"' ORDER BY
SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["MySQLConn"]);
这句话是声明一个实例加载驱动链接数据库
string cmdText = "SELECT * FROM send where name='"+username+"' ORDER BY id DESC"
声明一个变量SQL 根据用户名按照ID的降序排列.
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
创建一个Sqlcommand对象传入数据库名和SQL 语句
try
{
myConnection.Open();
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException ex)
{
throw new Exception(ex.Message,ex);
}
return dr;
}
打开数据库链接传入参数 并监控,成功返回dr 失败抛出异常
亲!