public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WebForm2 fg = new WebForm2();
string b = fg.rf();
this.TextBox1.Text = b;
string sqlcon = "server=lenovo-159d00cc;database=Dongman;uid=sa;pwd=123";
string sqlIt = "select safeA from [Login] where [accountName]='" + b + "'";
SqlConnection sql = new SqlConnection(sqlcon);
sql.Open();
SqlCommand cmd = new SqlCommand(sqlIt, sql);
string g = cmd.ExecuteScalar().ToString();
this.TextBox2.Text = g; }
}
此代码实现的是在页面载入时将上一个页面中输入的用户名带给本页中的Textbox1控件,并根据此用户名查询数据库找出与用户名对应的字段safeA的值,然后将此值显示在Textbox2控件上。但是实际运行时由前一页面载入此页时用户名没有带过来,而且如果不把后面查数据库的内容注释掉的话由前一页面载入时直接出现了“未将对象引用设置到对象的实例。”的错误。请问各位大侠哪里错了啊?如果要实现以上功能的话要怎么写啊?小弟我先谢谢了
{
protected void Page_Load(object sender, EventArgs e)
{
WebForm2 fg = new WebForm2();
string b = fg.rf();
this.TextBox1.Text = b;
string sqlcon = "server=lenovo-159d00cc;database=Dongman;uid=sa;pwd=123";
string sqlIt = "select safeA from [Login] where [accountName]='" + b + "'";
SqlConnection sql = new SqlConnection(sqlcon);
sql.Open();
SqlCommand cmd = new SqlCommand(sqlIt, sql);
string g = cmd.ExecuteScalar().ToString();
this.TextBox2.Text = g; }
}
此代码实现的是在页面载入时将上一个页面中输入的用户名带给本页中的Textbox1控件,并根据此用户名查询数据库找出与用户名对应的字段safeA的值,然后将此值显示在Textbox2控件上。但是实际运行时由前一页面载入此页时用户名没有带过来,而且如果不把后面查数据库的内容注释掉的话由前一页面载入时直接出现了“未将对象引用设置到对象的实例。”的错误。请问各位大侠哪里错了啊?如果要实现以上功能的话要怎么写啊?小弟我先谢谢了
解决方案 »
- 求一消息框源码,标题要长~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 关于继承模板页的子网页中Content窗口大小和位置的调整
- 初学问题,datdataReader.GetString(dataReader.GetOrdinal("MyFieldName")) 无法取值
- asp.net打包发布???
- post传送XML的问题
- asp.net怎么防止刷票呢?
- 提供繁体系统
- 文本翻页解决办法
- 有关VisualStudio 2005的问题(100分大谢)
- 本人刚学C#,在ASP.NET为什么不能使用Trim ,MessageBox.show 等,
- 兄弟们,我用asp.net做个OA系统,请大家给点建议
- 为什么我保存的网页都成了htm文件?
通过Server.Transfer实现传值
WebForm1 wf;
wf = (WebForm1)Context.Handler;
或URL传值
更多的信息楼主可以参考网上的资料。