Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    C#/ASP.NET Code Help

    Hello all,

    I'm new to this forum, and apologies if this is posted in the wrong place. I'm having some problems with some coding in the above languages. I have one particular problem, which I hope someone can help with.

    I am trying to populate a field on a web form, based on the selections made in two drop down boxes (Combination of the two). On selecting the drop down values, it performs a lookup in the database to pull back a value, and populates a text field with this value.

    I've got the SQL stored procedure covered, and the ASP.NET part of things. What I'm struggling on is the C# part. I have the following code so far:

    Code:
    private void GetPriority()
        {
    	clsServerDetails objServerDetails = new clsServerDetails();
            SqlConnection objSql = new SqlConnection();
            SqlCommand objCmd = new SqlCommand();
            SqlDataAdapter objDa = new SqlDataAdapter();
    
    	try
    	{
    	    objServerDetails.setConnectionInformation("Default");
                objSql.ConnectionString = objServerDetails.ConnectionString;
                objSql.Open();
                objCmd.CommandText = "CPortalGetPriority";
                objCmd.CommandType = CommandType.StoredProcedure;
                objCmd.Parameters.Add("@Impact", SqlDbType.NVarChar, 100).Value = ddImpact.Text;
                objCmd.Parameters.Add("@Severity", SqlDbType.NVarChar, 100).Value = ddUrgency.Text;
    //          objCmd.Connection = objSQL;
                objDa.SelectCommand = objCmd;
    
                objDa.Fill(txtPriority);
    	}
            catch (SqlException exSQL)
            {
                clsLogError.LogError("SqlException", exSQL.Number.ToString() + " " + exSQL.Message, System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                objDa.Dispose();
                objCmd.Dispose();
                objSQL.Close();
                objSQL.Dispose();
            }
        }
    However I get the following error on my page:

    Code:
    CS1502: The best overloaded method match for 'System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)' has some invalid arguments
    
    Source Error:
    
    Line 135:            objDa.SelectCommand = objCmd;
    Line 136:
    Line 137:            objDa.Fill(txtPriority);
    Line 138:	}
    Line 139:        catch (SqlException exSQL)
    I'm assuming I can't just fill the text field with the output of the stored procedure, so what's the best way about going about this?

    Thanks in anticipation of your replies.

    Mark Clayton
    Last edited by mdclaytz; 08-12-2011 at 10:48 AM.

  • #2
    New Coder
    Join Date
    Aug 2011
    Posts
    50
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I can't see where you declared the dataset txtpriority!

    Try to use the following:

    Code:
     Dim ds As New DataSet
                Dim da As New SqlDataAdapter(sqlCmd)
                da.Fill(ds)

  • #3
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,662
    Thanks
    41
    Thanked 189 Times in 188 Posts
    Quote Originally Posted by dotnetmind View Post
    I can't see where you declared the dataset txtpriority!

    Try to use the following:

    Code:
     Dim ds As New DataSet
                Dim da As New SqlDataAdapter(sqlCmd)
                da.Fill(ds)
    and to translate to C#

    Code:
    SqlDataSet ds_txtPriority = new SqlDataSet();
    
    .....
    
    objDa.Fill(ds_txtPriority);
    note i did this free hand and without checking syntaxes

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •