在ASP.NET中,我要在一些文本框中显示查询到的一条记录(用下拉框选择条件),下面的程序哪里有错?
protectedvoidDropDownList1_SelectedIndexChanged(objectsender,EventArgse){SqlConnectio...
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("uid=sa;pwd=;server=localhost;database=House;");
string sql = "select * from Area where Name='" + DDName.SelectedItem.Text + "'";
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
this.TextBox1.Text = reader[3].ToString();
this.TextBox2.Text = reader[4].ToString();
this.TextBox3.Text = reader[5].ToString();
this.TextBox4.Text = reader[6].ToString();
}
} 展开
{
SqlConnection conn = new SqlConnection("uid=sa;pwd=;server=localhost;database=House;");
string sql = "select * from Area where Name='" + DDName.SelectedItem.Text + "'";
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
this.TextBox1.Text = reader[3].ToString();
this.TextBox2.Text = reader[4].ToString();
this.TextBox3.Text = reader[5].ToString();
this.TextBox4.Text = reader[6].ToString();
}
} 展开
3个回答
2013-08-07
展开全部
可疑1:SqlConnection conn = new SqlConnection("uid=sa;pwd=;server=localhost;database=House;");//你的数据库没有密码吗?pwd=;可疑2:string sql = "select * from Area where Name='" + DDName.SelectedItem.Text + "'";
这个是不是应该写成:string sql="select * from Area where Name="+DDName.SelectedItem.Text;
这个是不是应该写成:string sql="select * from Area where Name="+DDName.SelectedItem.Text;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-07
展开全部
cmd.connection = conn;你落了这句了,在执行之前
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-07
展开全部
猛一看没什么错误 你不能说一下出了什么提示吗???
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询