请问各位高手这个程序是这样写吗?

rimpac 2009-04-21 04:17:10
各位高手好,小弟才开始学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];//显示出来
}


}
}
...全文
52 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧