java 将查询到的数据放到textbox,从数据表里查询出的一条记录,怎么实现按要求分别显示到相应的TextBox框中...

当前位置:我的异常网» C# » 从数据表里查询出的一条记录,怎么实现按要求分别显

从数据表里查询出的一条记录,怎么实现按要求分别显示到相应的TextBox框中

www.myexceptions.net  网友分享于:2013-01-02  浏览:26次

从数据表里查询出的一条记录,如何实现按要求分别显示到相应的TextBox框中

从数据表里查询出的一条记录,如何实现按要求分别显示到相应的TextBox框中

------解决方案--------------------

string QueryStr= "select * from tablename ";

OleDbCommand Cmd = new OleDbCommand(QueryStr, myConnection);

myConnection.Open();

OleDbDataReader dr= cmd.ExecuteReader();

try

{

while (dr.Read())

{

for (int i = 0; i < dr.FieldCount; i++)

{

if (myDataReader.GetName(i) == "columnsname1 ")

{

TextBox1.Text = dr.GetString(i);

}

if (dr.GetName(i) == "columnsname2 ")

{

TextBox2.Text = dr.GetString(i);

}

}

}

catch

{

}

finally

{

dr.Close();

myConnection.Close();

}

}

------解决方案--------------------

public DataTable getEmployeeDao()

{

return this.getEmployeeDao( "Employee ");

}

public DataTable getEmployeeDao(string Tablename)

{

DataTable dt = new DataTable(Tablename);

SqlConnection conn = ManageConn.getConnection();

SqlCommand cmd = new SqlCommand();

try

{

cmd.Connection = conn;

cmd.CommandText = "select EmpNo,CardID,EmpName, DeptName, CreateDate, Sex , JoinDay, Birthday , Duty , Nationstate, IDCard, MarryState,Tel, Addr , JTWeekName from employee where DimissionDay is null ";

SqlDataAdapter da = new SqlDataAdapter(cmd);

da.Fill(dt);

dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };

//dt.Columns[0].Unique = true;

// dt.Columns[2].Unique = true;

//dt.Columns[3].Unique = true;

}

catch (SqlException e1)

{

MessageBox.Show( "錯誤訊息: " + e1.Message, "錯誤提示 ");

return null;

}

catch (Exception e2)

{

MessageBox.Show( "錯誤訊息: " + e2.Message, "錯誤提示 ");

return null;

}

finally

{

cmd = null;

ManageConn.freeConnection(conn);

}

return dt;

}

public Employee()

{

InitializeComponent();

dao = new EmpDao();

ds = new DataSet();

ds.Tables.Add(dao.getEmployeeDao());

dv = new DataView(ds.Tables[ "Employee "]);

}

private void getEmployeInfo(int row)

{

DataRow dr1 = ds.Tables[ "Employee "].Rows[row];

textEmpNo.DataBindings.Add( "Text ", ds, "Employee.EmpNo ");

textCardID.DataBindings.Add( "Text ", ds, "Employee.CardID ");

textEmpName.DataBindings.Add( "Text ", ds, "Employee.EmpName ");

textDeptName.DataBindings.Add( "Text ", ds, "Employee.DeptName ");

textCreateDate.DataBindings.Add( "Text ", ds, "Employee.CreateDate ");

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值