Skip to content

Replies

0
Derek
Derek answered on Aug 27, 2010 6:02 PM

i fixed my final issue, had to do with what i named the textfield and valuefields….they didnt match up with what i was trying to pull with my SP. Thanks for all of your help!

0
Derek
Derek answered on Aug 27, 2010 4:09 PM

so i fixed the issue i was having before, now the page loads but in the ddl all it displays is System.Data.DataRowView

 

 

code behind:

WebDropDown1.DataSource =


 


dataAccess


.getEmployees();

WebDropDown1.TextField =


 


"Craftsperson"


;

WebDropDown1.ValueField =


 


"Craftsperson"


;

WebDropDown1.DataBind();

 

aspx:

 

 


 


 

<


ig


:


WebDropDown




ID


="WebDropDown1"




runat


="server"




Width


="200px">


 


 


 

</


ig


:


WebDropDown


>


your thoughts?

0
Derek
Derek answered on Aug 27, 2010 4:09 PM

so i fixed the issue i was having before, now the page loads but in the ddl all it displays is System.Data.DataRowView

 

 

code behind:

WebDropDown1.DataSource =


 


dataAccess


.getEmployees();

WebDropDown1.TextField =


 


"Craftsperson"


;

WebDropDown1.ValueField =


 


"Craftsperson"


;

WebDropDown1.DataBind();

 

aspx:

 

 


 


 

<


ig


:


WebDropDown




ID


="WebDropDown1"




runat


="server"




Width


="200px">


 


 


 

</


ig


:


WebDropDown


>


your thoughts?

0
Derek
Derek answered on Aug 26, 2010 10:20 PM

I am still having a bit of trouble getting this all figure out. I tried developing the dataset you mentioned inside my dataAccess.cs file, here is what i came up with:

 

 

    #region getEmployees()
    /// <summary>
    /// getEmployees()
    /// </summary>
    /// <returns></returns>
    public static DataSet getEmployees()
    {

        SqlConnection connection = null;
        try
        {
            connection = new SqlConnection(utilities.getConnectionString());
            SqlCommand command = new SqlCommand("dbo.spGetEmployees", connection);
            command.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataSet dsEmployees = new DataSet();
            adapter.Fill(dsEmployees, "fullname");

            connection.Open();
            return dsEmployees;
        }
        catch
        {
            if (connection != null)
                connection.Close();
            throw;
        }
    }
    #endregion

 

 

when i try to load the site i get a Cannot find the object 'spGetEmployees', because it does not exist or you do
not have permission.
i am not sure why it does this because i left the connection part of the code alone. Here is my SP, im not sure if that will help at all, it selects the id of the person and combines there first, last, middle names together.

 

SELECT user_id ,
ced_pref_sur + ', ' + ced_pref_giv + ' ' + ced_pref_mi AS fullname
FROM r1.dbo.database (NOLOCK)
ORDER BY fullname

I know this piece of code works correctly, i am worried that since the statement is selecting two values something is happening when the dataset is being loaded, but ultimately i am not sure (i have never used a dataSet before, im rather new to this)

Thanks again!

 

0
Derek
Derek answered on Aug 25, 2010 3:48 PM

Ok so this is what i tried:

                    SqlDataSource sds = new SqlDataSource();
                    sds.ConnectionString = WebConfigurationManager.ConnectionStrings["myConnectionString"].ToString();
                    sds.SelectCommand = "getEmployees";
                    sds.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;

                    WebDropDown1.DataSource = sds;
                    WebDropDown1.TextField = "Craftsperson";
                    WebDropDown1.ValueField = "Craftsperson";

 

 

 

This is what is in my dataAccess.cs file that i had been using to get to my store procedures:

    #region getEmployees()
    /// <summary>
    /// getEmployees()
    /// </summary>
    /// <returns></returns>
    public static SqlDataReader getEmployees()
    {
        SqlConnection connection = null;
        try
        {
            connection = new SqlConnection(utilities.getConnectionString());
            SqlCommand command = new SqlCommand("dbo.spGetEmployees", connection);
            command.CommandType = CommandType.StoredProcedure;

            SqlParameter returnValueParam = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
            returnValueParam.Direction = ParameterDirection.ReturnValue;
            command.Parameters.Add(returnValueParam);

            connection.Open();
            return command.ExecuteReader(CommandBehavior.CloseConnection);
        }
        catch
        {
            if (connection != null)
                connection.Close();
            throw;
        }
    }
    #endregion

 

 

when i run it on my site it get an

"Object reference not set to an instance of an object." error on my site. Am i just being thick and need to put something else in the code you gave me to get this to work?

 

Thanks for your help!

0
Derek
Derek answered on Aug 25, 2010 2:40 PM

Well the thing is that my connection string is in my web.config file, so i was trying to avoid using it in two places within the site.