c# datable display data

R8VI
R8VI used Ask the Experts™
on
HI,

I have the below code I am operating a 3 tier Arch, with presentation, business, and data layer.

I am getting a value Ifrom the DB I need to know how to display the value in the label

Please help

Thanks,

R8VI
Data Layer

 public DataTable LoadPropertyId(string sPropertyNumber, string sStreetName)

        string connStr = ConfigurationManager.ConnectionStrings["SplitfeeConnString"].ToString();
        SqlConnection conn = new SqlConnection(connStr);
        conn.Open();
        SqlCommand cmd = new SqlCommand("spGetPID", conn);
        cmd.CommandType = CommandType.StoredProcedure;


        DataTable DTpropID = new DataTable();

        try
        {

            cmd.Parameters.AddWithValue("@PropertyNumber", sPropertyNumber);
            cmd.Parameters.AddWithValue("@StreetName", 


            // Create new DataAdapter
            using (SqlDataAdapter sqlDataAdptGetPropertyID = new SqlDataAdapter("sp", conn))
            {

                sqlDataAdptGetPropertyID.Fill(DTpropID);


            }
        }
        catch
        {
            throw;
        }

        finally
        {
            cmd.Dispose();
            conn.Close();
            conn.Dispose();
        }

        return DTpropID; 

    }

Business layer

public DataTable LoadPropertyIdBAL(string sPropertyNumber, string sStreetName)
    {

        DataTable DTpropIDBAL = new DataTable();

        GetPropertyInfoDAL DataTablePropertyID = new GetPropertyInfoDAL();

        try
        {
            DataTablePropertyID.LoadPropertyId(sPropertyNumber, sStreetName);
        }
        catch
        {
            throw;
        }


        return DTpropIDBAL;
    }

Presentention layer

string sPropertyNumber = txtPropertyNumber.Text;
            string sStreetName = txtStreet.Text;
         

            GetPropertyInfoBAL PropertyID = new GetPropertyInfoBAL();

            PropertyID.LoadPropertyIdBAL(sPropertyNumber, sStreetName);

//need to display what is in the datatable in this text box             
            lblPropertyID.Text = "";

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Can u post the complete code of the stored procedure spGetPID.. can u also post all the table structures..
I need to modify ur code for all 3 layers.. I think you should post complete class Files.. and not just individual methods.. plus the backend's table structures..

Author

Commented:
HI,

The SP looks like this

CREATE PROCEDURE spGetPID

      @PropertyNumber VARCHAR(10),
    @StreetName VARCHAR(50),       


AS

      SELECT PropertyId
      FROM Prop      
            WHERE PropertyNumber =       @PropertyNumber
            AND Street = @StreetName


At the present time I only have this table and i only need info from this table

Please help

Thanks,

R8VI
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Author

Commented:
hi,

Thanks for all your help here is the complete code.

Please help

Thanks,

R8VI
Data Access layer 

public class GetPropertyInfoDAL
{
    public GetPropertyInfoDAL()
    {
    }
    /// <summary>
    /// Get Property ID
    /// </summary>
    /// <param name="PropertyNumber"></param>
    /// <param name="StreetName"></param>




    public DataTable LoadPropertyId(string sPropertyNumber, string sStreetName)
    {

        string connStr = ConfigurationManager.ConnectionStrings["Split"].ToString();
        SqlConnection conn = new SqlConnection(connStr);
        conn.Open();
        SqlCommand cmd = new SqlCommand("spGetPID", conn);
        cmd.CommandType = CommandType.StoredProcedure;


        DataTable DTpropID = new DataTable();

        try
        {

            cmd.Parameters.AddWithValue("@PropertyNumber", sPropertyNumber);
            cmd.Parameters.AddWithValue("@StreetName", 

            // Create new DataAdapter
            using (SqlDataAdapter sqlDataAdptGetPropertyID = new SqlDataAdapter("spGetPropertyID", conn))
            {

                sqlDataAdptGetPropertyID.Fill(DTpropID);


            }
        }
        catch
        {
            throw;
        }

        finally
        {
            cmd.Dispose();
            conn.Close();
            conn.Dispose();
        }

        return DTpropID; 

    }
}


Business layer

public class GetPropertyInfoBAL
{
    public GetPropertyInfoBAL()
    {
    }
    /// <summary>
    /// Get Property ID
    /// </summary>
    /// <param name="PropertyNumber"></param>
    /// <param name="StreetName"></param>


    public DataTable LoadPropertyIdBAL(string sPropertyNumber, string sStreetName)
    {

        DataTable DTpropIDBAL = new DataTable();

        GetPropertyInfoDAL DataTablePropertyID = new GetPropertyInfoDAL();

        try
        {
            DataTablePropertyID.LoadPropertyId(sPropertyNumber, sStreetName);
        }
        catch
        {
            throw;
        }


        return DTpropIDBAL;
    }

}

Open in new window

By the way I have modified your code there were some syntax errors in the code... Here is the corrected code.. But hey you need to change the Column Name for Property Id Column at the last line .. I assumed that the name of the column was "PropertyID" :
Data Layer

 public DataTable LoadPropertyId(string sPropertyNumber, string sStreetName)
 {
     string connStr = ConfigurationManager.ConnectionStrings["SplitfeeConnString"].ToString();
        SqlConnection conn = new SqlConnection(connStr);
        conn.Open();
        SqlCommand cmd = new SqlCommand("spGetPID", conn);
        cmd.CommandType = CommandType.StoredProcedure;


        DataTable DTpropID = new DataTable();

        try
        {

            cmd.Parameters.AddWithValue("@PropertyNumber", sPropertyNumber);
            cmd.Parameters.AddWithValue("@StreetName", sStreetName);


            // Create new DataAdapter
            using (SqlDataAdapter sqlDataAdptGetPropertyID = new SqlDataAdapter(cmd))
            {
                sqlDataAdptGetPropertyID.Fill(DTpropID);
            }
        }
        catch
        {
            throw;
        }

        finally
        {
            cmd.Dispose();
            conn.Close();
            conn.Dispose();
        }

        return DTpropID; 
    }

Business layer

public DataTable LoadPropertyIdBAL(string sPropertyNumber, string sStreetName)
{

     DataTable DTpropIDBAL = new DataTable();

     GetPropertyInfoDAL DataTablePropertyID = new GetPropertyInfoDAL();

     try
     {
         DTpropIDBAL = DataTablePropertyID.LoadPropertyId(sPropertyNumber, sStreetName);
     }
     catch
     {
         throw;
     }

     return DTpropIDBAL;

}

Presentention layer

string sPropertyNumber = txtPropertyNumber.Text;
string sStreetName = txtStreet.Text;
         

GetPropertyInfoBAL PropertyID = new GetPropertyInfoBAL();

DataTable dt = PropertyID.LoadPropertyIdBAL(sPropertyNumber, sStreetName);

//need to display what is in the datatable in this text box             

lblPropertyID.Text = dt.Rows[0]["PropertyID"].ToString();

Open in new window

Ok so you need to use "PropertyId" instead of "PropertyID" in line 76 of above solution..
All the code should be same except for line 76  It should be this :
lblPropertyID.Text = dt.Rows[0]["PropertyID"].ToString();

Open in new window

Sorry like this :
lblPropertyID.Text = dt.Rows[0]["PropertyId"].ToString();

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial