主题:郁闷一天咯,回答给高分!(关于SQL的)
存储过程为:
CREATE PROCEDURE Get
@userName varchar
AS
select * from T_UserInfo
where @userName = UserName
GO
------------------------------------
表 T_UserInfo
UserName UserPWD
a a
asd asd
-------------------------------------
代码:
using System;
using System.Data;
using System.Data.SqlClient;
class A
{
public static void Main()
{
string userName = "aa";
string strConn = "server=(local);database=BookManagerSystem;Trusted_Connection=yes;";
SqlConnection conn = new SqlConnection(strConn);
SqlCommand comm = new SqlCommand("Get", conn);
comm.CommandType = CommandType.StoredProcedure;
try
{
conn.Open();
comm.Parameters.Add("@userName", SqlDbType.NVarChar);
comm.Parameters["@userName"].Value = userName;
SqlDataReader reader = comm.ExecuteReader();
while(reader.Read())
{
Console.WriteLine(reader["UserName"]);
Console.WriteLine(reader["UserID"]);
Console.WriteLine(reader["UserPWD"]);
Console.WriteLine(reader["UserPop"]);
}
}
catch(Exception ex)
{
Console.WriteLine( ex);
}
finally
{
conn.Close();
}
Console.ReadLine();
}
}
--------------------------------------------------
运行结果
a
a
---------------------------------------------------
为什么输入的asd,却返回a的内容?哪里有问题?
CREATE PROCEDURE Get
@userName varchar
AS
select * from T_UserInfo
where @userName = UserName
GO
------------------------------------
表 T_UserInfo
UserName UserPWD
a a
asd asd
-------------------------------------
代码:
using System;
using System.Data;
using System.Data.SqlClient;
class A
{
public static void Main()
{
string userName = "aa";
string strConn = "server=(local);database=BookManagerSystem;Trusted_Connection=yes;";
SqlConnection conn = new SqlConnection(strConn);
SqlCommand comm = new SqlCommand("Get", conn);
comm.CommandType = CommandType.StoredProcedure;
try
{
conn.Open();
comm.Parameters.Add("@userName", SqlDbType.NVarChar);
comm.Parameters["@userName"].Value = userName;
SqlDataReader reader = comm.ExecuteReader();
while(reader.Read())
{
Console.WriteLine(reader["UserName"]);
Console.WriteLine(reader["UserID"]);
Console.WriteLine(reader["UserPWD"]);
Console.WriteLine(reader["UserPop"]);
}
}
catch(Exception ex)
{
Console.WriteLine( ex);
}
finally
{
conn.Close();
}
Console.ReadLine();
}
}
--------------------------------------------------
运行结果
a
a
---------------------------------------------------
为什么输入的asd,却返回a的内容?哪里有问题?