Overload

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DaveRook
    New Member
    • Jul 2007
    • 147

    Overload

    Hello

    I am getting a CS1502: The best overloaded method match for 'System.Data.Sq lClient.SqlData Adapter.SqlData Adapter(System. Data.SqlClient. SqlCommand)' has some invalid arguments

    I have no idea what I've done wrong!

    Code:
    string strConn = ConfigurationManager.ConnectionStrings["BoardToBoard"].ConnectionString;
    
            string strB2BSQL = "SELECT * FROM View_BoardToBoard";
    
            SqlConnection B2BConn;
            DataSet ds = new DataSet();
            SqlDataAdapter B2BDA;
            
            B2BConn = new SqlConnection(strConn);
            B2BDA = new SqlDataAdapter(strB2BSQL);
    
            try
            {
                B2BConn.Open();
    
                B2BDA.Fill(ds, "B2B");
    
                grdB2B.DataSource = ds;
                grdB2B.DataBind();
            }
    
            finally
            {
                B2BConn.Close();
            }
    Thank you

    Dave
    Last edited by DaveRook; Apr 29 '09, 12:37 PM. Reason: A slight change gave a different issue!
  • Meganutter
    New Member
    • Mar 2009
    • 47

    #2
    try making a new SqlDataAdapter the moment you define it by adding
    Code:
    new SqlDataAdapter();
    that should fix it

    Comment

    • DaveRook
      New Member
      • Jul 2007
      • 147

      #3
      Thank you for the suggestion, but I've changed it a bit now and have something else.

      I have used this lots with Acces databases, but this is the first SQL server I'm trying to connect to

      Comment

      • Meganutter
        New Member
        • Mar 2009
        • 47

        #4
        what do you have now, could you paste some of the code and tell where the error points to?

        Comment

        • DaveRook
          New Member
          • Jul 2007
          • 147

          #5
          Sorry, I updated my original Post. What you have at the top of the page is what I have. I will add changes to new posts from now on.

          The error is on line 10: B2BDA = new SqlDataAdapter( strB2BSQL);


          Thank you

          Comment

          • Meganutter
            New Member
            • Mar 2009
            • 47

            #6
            to use a string in a new database you need to include a connection or connectionstrin g as well, try:
            Code:
            B2BDA = new SqlDataAdapter(strB2BSQL, B2BConn);

            Comment

            • DaveRook
              New Member
              • Jul 2007
              • 147

              #7
              Thank you for your help. It worked fine. If you have a minute more, can you tell me why I needed both?

              Line 9 B2BConn = new SqlConnection(s trConn); already tells it what the connection is so I don't know why I needed to declare it in the SqlDataAdapter as well

              Thank you again

              Comment

              • Meganutter
                New Member
                • Mar 2009
                • 47

                #8
                (im also quite new to programming, but ill try my best)
                a DataAdapter is the bridge between the application and the SQL server, so in order to get the data it needs to know how to connect. for that a connection string or connection object is used.
                when you use or create a SqlCommand Object it also asks for a connection.

                i hope to have explained it well

                Comment

                • DaveRook
                  New Member
                  • Jul 2007
                  • 147

                  #9
                  Superb. Thank you for your help.

                  Comment

                  Working...