private System.Data.SqlClient.SqlConnection conn;
string sql="select Name,Password from Register where (Name='"+this.textBox1.Text+"')and(Password='"+this.textBox2.Text+"')";
this.sqlCommand1.CommandText=sql;
this.sqlCommand1.Connection=this.conn;
this.sqlCommand1.Connection.Open(); SqlDataReader reader=this.sqlCommand1.ExecuteReader();
。。
reader.close();
this.sqlCommand1.Connection.Close();
这样使用哪里有错啊?
提示这样的错误
未处理的“System.InvalidOperationException”类型的异常出现在 system.data.dll 中
string sql="select Name,Password from Register where (Name='"+this.textBox1.Text+"')and(Password='"+this.textBox2.Text+"')";
this.sqlCommand1.CommandText=sql;
this.sqlCommand1.Connection=this.conn;
this.sqlCommand1.Connection.Open(); SqlDataReader reader=this.sqlCommand1.ExecuteReader();
。。
reader.close();
this.sqlCommand1.Connection.Close();
这样使用哪里有错啊?
提示这样的错误
未处理的“System.InvalidOperationException”类型的异常出现在 system.data.dll 中
conn = new System.Data.SqlClient.SqlConnection();
了吗?
这里conn.open()和this.sqlCommand1.Connection.Open();的作用不一样吗?
我加了句conn.ConnectionString=sql;
错误又成这样了
其他信息:在连接子字符串“select Name,Password from Register where Name='admin' and Password='admin'”中需要“;”分隔符。这句sql语句感觉没地方错呀。困惑
改成this.conn.Connection.Open();
还有这样的?不行吧。
using System.Data.SqlClient;
class Dbconn
{
}
(如果是 sql 的话)
它是这样的
郁闷啊。刚才的还是不知道出什么问题。
我是初学者,我好菜。多多学习
谢谢个位哦