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类型
           最匹配的重载方法具有一些无效参数!
我不会改,求指教

解决方案 »

  1.   

    connecionString没有拼写错误吗?
    还是
    connectionString这个节点存在吗
    配置文件里面appSettings节点里面有这个节点吗
      

  2.   

    是我的拼写错误,但是还是那两个错误,错误 4 参数“2”: 无法从“string”转换为“System.Data.SqlClient.SqlConnection” D:\C#\firstDemo\firstDemo\frmLogin.cs 45 168 firstDemo
    错误 3 与“System.Data.SqlClient.SqlCommand.SqlCommand(string, System.Data.SqlClient.SqlConnection)”最匹配的重载方法具有一些无效参数 D:\C#\firstDemo\firstDemo\frmLogin.cs 45 39 firstDemo
      

  3.   

    SqlCommand第二个参数只能接受连接类型,也就是说你读到连接字符串,还得实例化一个连接,这么写:
    [code]
    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = ConfigurationSettings.AppSettings.Get("connecionString");
    conn.Open();
    [/code]
    然后再写后面的代码,估计就可以了,其实就是SqlCommand第二个参数不能接受string。至于那个配置文件的节点有没有写错,我估计也错了,但是那个错了不是提示你说的错误。
      

  4.   

    string conn = ConfigurationSettings.AppSettings.Get("connecionString");
    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 );
      

  5.   

    SqlCommand第2个参数需要一个SqlConnection 对象的实例
      

  6.   


    SqlConnection conn=new Sqlconnection();
    conn.ConnectionString = ConfigurationSettings.AppSettings.Get("connecionString");
    SqlCommand cmd......后面接着写,就可以解决你说的问题
      

  7.   

    我猜,我应该这段都写错了!
    我想请问你一下,app.config里面的数据库配置怎么写,然后在窗体中调用数据库连接怎么调用?代码给我看下。我猜我这些地方写错了!
      

  8.   

    #region 连接字符串
            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);
            }
      

  9.   


    用习惯了xxHelper.cs
    叫我不用xxHelper还真操作不了数据库
      

  10.   

    关于APP.CONFIG里面对APP.SETTING和configuration的设置代码怎么弄啊?