string conn = ConfigurationSettings.AppSettings.Get("connecionString");
SqlCommand cmd = new SqlCommand("select count(*) from tb_Admin where AdminUser='" + textBox1.Text + "' and Adminpassword='" + textBox2.Text + "'",conn);
int i = Convert.ToInt32(cmd.ExecuteScalar());
{
}
错误提示是:参数2无法转换成string类型
最匹配的重载方法具有一些无效参数!
我不会改,求指教
SqlCommand cmd = new SqlCommand("select count(*) from tb_Admin where AdminUser='" + textBox1.Text + "' and Adminpassword='" + textBox2.Text + "'",conn);
int i = Convert.ToInt32(cmd.ExecuteScalar());
{
}
错误提示是:参数2无法转换成string类型
最匹配的重载方法具有一些无效参数!
我不会改,求指教
还是
connectionString这个节点存在吗
配置文件里面appSettings节点里面有这个节点吗
错误 3 与“System.Data.SqlClient.SqlCommand.SqlCommand(string, System.Data.SqlClient.SqlConnection)”最匹配的重载方法具有一些无效参数 D:\C#\firstDemo\firstDemo\frmLogin.cs 45 39 firstDemo
[code]
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationSettings.AppSettings.Get("connecionString");
conn.Open();
[/code]
然后再写后面的代码,估计就可以了,其实就是SqlCommand第二个参数不能接受string。至于那个配置文件的节点有没有写错,我估计也错了,但是那个错了不是提示你说的错误。
SqlCommand cmd = new SqlCommand("select count(*) from tb_Admin where AdminUser='" + textBox1.Text + "' and Adminpassword='" + textBox2.Text + "'",conn);
应该改成
string connString = ConfigurationSettings.AppSettings.Get("connecionString");
SqlConnection cn = new SqlConnection(connString );
cn.Open();
SqlCommand cmd = new SqlCommand("select count(*) from tb_Admin where AdminUser='" + textBox1.Text + "' and Adminpassword='" + textBox2.Text + "'",cn );
SqlConnection conn=new Sqlconnection();
conn.ConnectionString = ConfigurationSettings.AppSettings.Get("connecionString");
SqlCommand cmd......后面接着写,就可以解决你说的问题
我想请问你一下,app.config里面的数据库配置怎么写,然后在窗体中调用数据库连接怎么调用?代码给我看下。我猜我这些地方写错了!
const string CONNSTRING = "server=.;database=Library;Trusted_connection=true";
static SqlConnection conn = new SqlConnection(CONNSTRING);
public static SqlConnection Conn
{
get { return DBsql.conn; }
}
#endregion #region 打开连接
public static void Open()
{
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
else if(conn.State== ConnectionState.Broken)
{
conn.Close();
conn.Open();
}
}
#endregion #region 关闭连接
public static void Close()
{
if (conn.State == ConnectionState.Closed || conn.State == ConnectionState.Broken)
{
conn.Close();
}
}
#endregion
public static void Ti(string sql,ref SqlDataReader reader)
{
SqlCommand comm = new SqlCommand(sql, conn);
Open();
reader = comm.ExecuteReader(CommandBehavior.CloseConnection);
}
用习惯了xxHelper.cs
叫我不用xxHelper还真操作不了数据库