I am new to C# and i am stuck when i try to fetch the data from SQL Server to Visual studio. I am writing the code as a n-tier application - Data Access, Business logic and the front end. I am fetching data in a disconnected env. I am able to retrive data in a grid view but, I am not able to fetch in my TB.
Here's my code so far-

DataAccess Layer:

 public DataTable EditCustomer(string query, string queryType, List<SqlParameter> parameters)
            DataSet ds;
            conn = new SqlConnection("Data Source=Laptop-HP\\SQLEXPRESS;Initial Catalog=Banking_new;Integrated
            cmd = new SqlCommand(query, conn);
            if (queryType == "SPS")
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandType = CommandType.Text;
            if (parameters != null)
                if (parameters.Count > 0)
                    foreach (SqlParameter param in parameters)
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    ds = new DataSet();
                    return ds.Tables[0];
                catch (Exception ex)
                    throw new Exception(ex.Message);
            return null;

Business Logic:

 public DataTable editCustomer()
            DataAccessLayer.DataManager objEditData = new DataAccessLayer.DataManager();
            List<SqlParameter> param = new List<SqlParameter>();
            return objEditData.EditCustomer("select * from customer where customerid = '100'", "Text", param);


 protected void Button4_Click(object sender, EventArgs e)
            CustomerEntities.Customer objEdit = new CustomerEntities.Customer();
            objEdit.CustId = TextBox1.Text;

            BusinessLayer.Program objBussEdit = new BusinessLayer.Program();

            GridView1.DataSource = objBussEdit.editCustomer();

I am not able to assign the datatable values to the textboxes.

Please help.

Try this..

SqlConnection Conn = new SqlConnection(Connection_String);
SqlCommand Comm = new SqlCommand(Command, Conn);
SqlDataReader srd = Comm.ExecuteReader();
if (srd.Read())
    textBox.Text = srd.GetValue(0).ToString();

P.S:This just a example change it according to your requirement

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.