string temp = txt姓名查找.Text; string ConStr = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
using (SqlConnection conn = new SqlConnection(ConStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText =@"Select *from T_Person where Name LIKE '%:temp%'";
using (SqlDataReader read=cmd.ExecuteReader())
{
while(read.Read())
{
if (lbx模糊显示.Text == "")
{
lbx模糊显示.Text = Convert.ToString(read.GetOrdinal("Name")) ;
}
else
{
lbx模糊显示.Text = lbx模糊显示.Text + Convert.ToString(read.GetOrdinal("Name")) ;
}
}
MessageBox.Show(Convert.ToString(read.GetOrdinal("Name")));
} }
if (lbx模糊显示.Text != "")
{
lbx模糊显示.Visible = true;
}
else
{
lbx模糊显示.Visible = false;
}
}赋值给cmd.CommandText 语句格式要怎么写?错那里?我用ExecuteReader()可以吗?
这个程序错那里呢?
using (SqlConnection conn = new SqlConnection(ConStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText =@"Select *from T_Person where Name LIKE '%:temp%'";
using (SqlDataReader read=cmd.ExecuteReader())
{
while(read.Read())
{
if (lbx模糊显示.Text == "")
{
lbx模糊显示.Text = Convert.ToString(read.GetOrdinal("Name")) ;
}
else
{
lbx模糊显示.Text = lbx模糊显示.Text + Convert.ToString(read.GetOrdinal("Name")) ;
}
}
MessageBox.Show(Convert.ToString(read.GetOrdinal("Name")));
} }
if (lbx模糊显示.Text != "")
{
lbx模糊显示.Visible = true;
}
else
{
lbx模糊显示.Visible = false;
}
}赋值给cmd.CommandText 语句格式要怎么写?错那里?我用ExecuteReader()可以吗?
这个程序错那里呢?
可以帮看下代码吗?那里有错,谢谢!
不过我是换成DataSet来实现的。
但为什么ExecuteReader不行,我还是不懂。
总之谢谢您的帮助!