我正在测试我对 ADO.NET 和 SQL 的了解,目前正在尝试做基础知识。我想从表中读取,当用户单击按钮时,会弹出一个消息框,其中包含 ApplicationName 列中的值。
当我单击按钮时,它目前没有做任何事情......有什么想法吗?
protected void TestSubmit_ServerClick(对象发送者,EventArgs e)
{
// 初始化数据库连接器。
SqlConnection connectSQL = new SqlConnection();
// 发送连接字符串。
connectSQL.ConnectionString = @"数据源 = localhost\SQLEXPRESS;" +
“初始目录 = 输入;集成安全 = SSPI”;
尝试
{
// 设置我们的命令。
SqlCommand theCommand = new SqlCommand("SELECT * FROM Inputs", connectSQL);
// 在文本框中写入存储的值。
连接SQL.Open();
SqlDataReader 读取器;
theReader = theCommand.ExecuteReader();
theReader.Read();
MessageBox(theReader["ApplicationName"].ToString());
theReader.Close();
连接SQL.Close();
}
捕获(异常 ee)
{
MessageBox("哎呀:" + ee);
}
私人无效消息框(字符串味精)
{
标签 lbl = 新标签();
lbl.Text = "" + Environment.NewLine + "window.alert('" + msg + "')";
Page.Controls.Add(lbl);
}