请问各位高手这个程序是这样写吗?
各位高手好,小弟才开始学C#和.NET 编了个页面要从“员工数据库”的表中获取员工的信息,由(员工姓名EmployeesName;员工工号EmployeesID;员工性别EmployeesSex)几个内容。
运行后无法显示从数据库的返回值,各位高手帮忙看看哪里错了。
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
public string sqlconnnect(string employeesName)
{
SqlConnection cnn = new SqlConnection("Data Source=172.22.8.27;User ID=be20;PWD=goodway5478;Initial Catalog=MSDI_Test;Persist Security Info=False;Pooling=true;Min Pool Size=50;Max Pool Size=500");//连接数据库
cnn.Open();
SqlCommand thiscommand = cnn.CreateCommand();
thiscommand.CommandText = "SELECT EmployeesID FROM EmployeesInfo WHERE EmployeesName=employeesName";
SqlDataReader thisreader = thiscommand.ExecuteReader();
//return thisreader;
string[] eminfo = new string[20];
int i = 0;
while (thisreader.Read())
{
// eminfo=thisreader["EmployeesID"];
eminfo[i] = thisreader.GetString(0);//将数据库EmployeesInfo表中的数据放到eminfo数组中
i++;
}
thisreader.Close();
cnn.Close();
return eminfo[i];
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string employeerName = TextemployeesNmae.Text;//读取用户输入字符
string[] emp= new string[20];;
for (int a = 0; a < 20; a++)
{
emp[a] = sqlconnnect(employeerName);//将返回值放入emp数组中
}
for(int i=0;i<20;i++)
{
TextBox1.Text = emp[i];//显示出来
}
}
}