是WEB程序        //read HotKey from database
        SqlLoadHotKey.SelectCommand = "SELECT HotKey FROM [TableHotkey] where ID = 1";
        string s = 上面命令执行的结果我的意思是如何执行上面的语句后,把返回结果给s.
HotKey字段在表中是字符串格式

解决方案 »

  1.   

    try..SqlConnection con=new SqlConnection("连接字符串");
    SqlLoadHotKey.SelectCommand = "SELECT HotKey FROM [TableHotkey] where ID = 1";
    SqlLoadHotKey.SelectCommand.Connection=con;
    con.Open();
    string s=Convert.ToString(SqlLoadHotKey.SelectCommand.ExecuteScalar());
    con.Close();
      

  2.   

    SqlConnection sqlCon = new SqlConnection("Data Source =(local);Integrated Security = SSPI;Initial Catalog = EduDB;");
            sqlCon.Open();
            string str1 = "SELECT HotKey FROM [TableHotkey] where ID = 1";
            SqlDataSource sqlHotKey1 = new SqlDataSource(sqlCon, str1);
            hotkey1.Text=Convert.ToString(sqlHotKey1.SelectCommand.
                这个点后面没有ExecuteScalar()方法啊
      

  3.   

    sorry...我不知道是SqlDataSource..
      

  4.   

    MSDN..// Returns a collection of NorthwindEmployee objects.
    public static ICollection GetAllEmployees () {
      ArrayList al = new ArrayList();  ConnectionStringSettings cts = ConfigurationManager.ConnectionStrings["NorthwindConnection"];  SqlDataSource sds
        = new SqlDataSource(cts.ConnectionString, "SELECT EmployeeID FROM Employees");  try {    IEnumerable IDs = sds.Select(DataSourceSelectArguments.Empty);    // Iterate through the Enumeration and create a
        // NorthwindEmployee object for each ID.
        foreach (DataRowView row in IDs) {
          string id = row["EmployeeID"].ToString();
          NorthwindEmployee nwe = new NorthwindEmployee(id);
          // Add the NorthwindEmployee object to the collection.
          al.Add(nwe);
        }
      }
      finally {
        // If anything strange happens, clean up.
        sds.Dispose();
      }  return al;
    }
      

  5.   

    try..string sqlCon="Data Source =(local);Integrated Security = SSPI;Initial Catalog = EduDB;";
    string str1 = "SELECT HotKey FROM [TableHotkey] where ID = 1";
    SqlDataSource sqlHotKey1 = new SqlDataSource(sqlCon, str1);
    IEnumerable IDs = sds.Select(DataSourceSelectArguments.Empty);
    DataGridView row=(DataGridView)IDs[0];
    hotkey1.Text=row["HotKey"];
      

  6.   

    平台是ASP.NET 2.0 用C#语言实现。
    其实我想做的功能是主页面上有5个HyperLink,然后在页面Load的时候从后台数据库中读取HotKey表中的数据然后分别给5个HyperLink的Text属性。请问如何实现起来最简单呢?数据库名为EduDB   表名为TableHotKey
      

  7.   

    那为什么不直接读呢?
    比如说你读ID=1的..SqlConnection con=new SqlConnection("连接字符串");
    SqlCommand cmd=new SqlCommand("SELECT HotKey FROM [TableHotkey] where ID = 1";);
    con.Open();
    string hotkey1.Text=Convert.ToString(cmd.ExecuteScalar());
    con.Close();
      

  8.   

    行了,你MSN在吗。我原来加你一直没信儿啊