[求助]数据库返回至问题
using System;using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data.Odbc;
using System.Configuration;
namespace StudentManagementSystem
{
class c_MDIManagement
{
string str_username;
int i_userType;
SqlConnection conn = new SqlConnection("server=.;pwd=sun;user id=sa;database=SIM");
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
public c_MDIManagement(string str)
{
str_username = str.Trim();
}
public int user_Type()
{
try
{
conn.Open();
string str_UserType = "select t_UserType from tb_UserInfo where t_UserName='" + str_username + "'";
= str_UserType;
cmd.Connection = conn;
dr = cmd.ExecuteReader();
if (dr.Read())
{
i_userType = Convert.ToInt32(dr["t_UserType"].ToString());
}
else
{
i_userType = 111;
}
conn.Close();
}
finally
{
conn.Close();
}
return i_userType;
}
}
}
我应改返回的是数据库中的t_UserType,而实际返回的是111或是0,这是哪的错?