定期在某些文本框中显示查询值 [英] show a query value in some textboxes regularly

查看:152
本文介绍了定期在某些文本框中显示查询值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何定期在某些文本框中显示sql查询,我的查询有3个答案,我想在3个文本框中显示,我可以使用ExecuteScalar还是使用Listbox或recordset?我该怎么做?我应该使用循环,但是如何使用?

How can I show sql query in some textboxes regularly I mean my query has for example 3 answer and I want to show them in 3 textboxes,can I use ExecuteScalar or use Listbox or recordset?how can I do this?I think I should use a loop but how?

推荐答案

//创建连接并进行连接,然后执行sql语句

// Create the connection and connect then execute sql statement

string str = "SELECT EmployeeID, FirstName, LastName FROM  Employees";

SqlCommand myDataReader = new SqlCommand(str, con);

myDataReader.Read();

if (myDataReader.HasRows)
{
  while (myDataReader.Read())
  {
    txtFName.Text = myDataReader.GetString("FName").ToString();
    txtLName.Text = myDataReader.GetString("LName").ToString();
    txtNName.Text = myDataReader.GetString("EmployeeID").ToString();

  }
}
// Nothing was found based on Search Criteria, Tell the System
else
{
  MessageBox.Show("No matches were found, try again.");
}
  myDataReader.Close();




问候.




Regards.


这篇关于定期在某些文本框中显示查询值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆