Hello,
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
Security=SSPI");
cmd = new SqlCommand(query, conn);
if (queryType == "SPS")
cmd.CommandType = CommandType.StoredProcedure;
else
cmd.CommandType = CommandType.Text;
if (parameters != null)
{
if (parameters.Count > 0)
{
foreach (SqlParameter param in parameters)
cmd.Parameters.Add(param);
}
try
{
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
conn.Close();
}
}
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);
}
FrontEnd:
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();
GridView1.DataBind();
}
I am not able to assign the datatable values to the textboxes.
Please help.