是WEB程序 //read HotKey from database
SqlLoadHotKey.SelectCommand = "SELECT HotKey FROM [TableHotkey] where ID = 1";
string s = 上面命令执行的结果我的意思是如何执行上面的语句后,把返回结果给s.
HotKey字段在表中是字符串格式
SqlLoadHotKey.SelectCommand = "SELECT HotKey FROM [TableHotkey] where ID = 1";
string s = 上面命令执行的结果我的意思是如何执行上面的语句后,把返回结果给s.
HotKey字段在表中是字符串格式
SqlLoadHotKey.SelectCommand = "SELECT HotKey FROM [TableHotkey] where ID = 1";
SqlLoadHotKey.SelectCommand.Connection=con;
con.Open();
string s=Convert.ToString(SqlLoadHotKey.SelectCommand.ExecuteScalar());
con.Close();
sqlCon.Open();
string str1 = "SELECT HotKey FROM [TableHotkey] where ID = 1";
SqlDataSource sqlHotKey1 = new SqlDataSource(sqlCon, str1);
hotkey1.Text=Convert.ToString(sqlHotKey1.SelectCommand.
这个点后面没有ExecuteScalar()方法啊
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;
}
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"];
其实我想做的功能是主页面上有5个HyperLink,然后在页面Load的时候从后台数据库中读取HotKey表中的数据然后分别给5个HyperLink的Text属性。请问如何实现起来最简单呢?数据库名为EduDB 表名为TableHotKey
比如说你读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();