我用的是VS2005,下面的代码提示错误!
问题1:
ConnDB us = new ConnDB();
SqlCommand cmd=new SqlCommand();
cmd.Connection = us.Cn;
cmd.CommandText="select * from Users where UserCode='" + textBox1.Text +"'";
cmd.CommandType = CommandType.Text;
SqlDataReader logi = cmd.ExecuteReader();
运行到最后一行时提示:Invalidoperationexception was unhandled
ExecuteReader:Connection propertyh has not been initialized.
但是之前运行都没错的啊问题2:在窗体中按回车键时,默认到某个按钮上,或是按ESC键时默认到某个键,在哪里设置呢!
谢谢!
问题1:
ConnDB us = new ConnDB();
SqlCommand cmd=new SqlCommand();
cmd.Connection = us.Cn;
cmd.CommandText="select * from Users where UserCode='" + textBox1.Text +"'";
cmd.CommandType = CommandType.Text;
SqlDataReader logi = cmd.ExecuteReader();
运行到最后一行时提示:Invalidoperationexception was unhandled
ExecuteReader:Connection propertyh has not been initialized.
但是之前运行都没错的啊问题2:在窗体中按回车键时,默认到某个按钮上,或是按ESC键时默认到某个键,在哪里设置呢!
谢谢!
解决方案 »
- wpf 后台操作自定义控件
- for循环使用timer的问题
- 關于一個數據庫鏈接的問題
- Bitmap位图比较,很棘手,寻找高手
- 大家说说ListView与DataGridView的区别吧?
- C#做WINFORM窗体在操作EXCEL导入数据时数据源路径发生改变,导致后面程序对ACCESS操作十找不到数据库
- c#如何获取字符串的前50个字符?
- 做电脑几年了,病也做出来了,郁闷中,痛苦中!求治疗的好方法!非常感谢!
- 关于DataGrid的背景色设定!
- 要在sql2000中保存jpg,数据库要用什么数据类型,还有怎么读出来?请帮忙
- 老问题
- Connection用了Dispose()后还要用Connection = null吗?
然后 private void Form2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
this.button1.Focus();
}
else if(e.KeyCode == Keys.Enter)
{
this.button2.Focus();
} }