我对以下问题感到困惑;
我正在尝试使用SqlDataReader检索记录(列'EmployeeId'(int)).
当我直接在服务器上运行查询时,我正确地获得了记录.当我运行相同的过程来获取另一列(字符串)时,我正确地获得了记录.
我认为问题是由于我试图获得一个int,程序跳过了
while (mySqlDbDataReader.Read())
Run Code Online (Sandbox Code Playgroud)
并直接去
catch (Exception eMsg1)
{
Run Code Online (Sandbox Code Playgroud)
这是完整的程序
public string getUserId()
{
//Check user details against login in Db
//Local variables to capture values from Db
string varId = "";
//Connection string
conn = sqlDbConnection.GetConnection();
SqlCommand newCmd = conn.CreateCommand();
newCmd.Connection = conn;
newCmd.CommandType = CommandType.Text;
//Query
userCredentials connectedUser = new userCredentials();
newCmd.CommandText = "SELECT EmployeeId FROM tblEmployees WHERE WinLogin='" + connectedUser.getWindowsLogin() + "';";
//Connect
newCmd.Connection = conn;
conn.Open();
//Utilisation du try-catch permettant de fermer …Run Code Online (Sandbox Code Playgroud)