Showing posts with label Dataset with where Clause. Show all posts
Showing posts with label Dataset with where Clause. Show all posts

Wednesday, March 18, 2009

Dataset with where Clause

On A button Click event we get all the Values of Customer Table(CustomerName, CustomerAddress, CustomerAge, CustomerPhone) through Customer ID which is present in the Query String.

protected void btnGet_Click(object sender, EventArgs e)
{
int customerid = Convert.ToInt32(Request.QueryString["CustomerId"].ToString());
SqlParameter objParameter = new SqlParameter();
SqlCommand objCommand = new SqlCommand();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["test"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("SELECT CustomerID, CustomerName, CustomerPhone, CustomerAddress, CustomerAge " +
"FROM Customer where CustomerID=@CustomerID", conn);
da.SelectCommand.Parameters.Add(new SqlParameter("@CustomerID", customerid));
da.SelectCommand.Parameters["@CustomerID"].Value = customerid;
DataSet ds = new DataSet();
da.Fill(ds, "Customer");
foreach (DataRow pRow in ds.Tables["Customer"].Rows)
{
tbxCustomerName.Text = pRow["CustomerName"].ToString();
tbxCustomerPhone.Text = pRow["CustomerPhone"].ToString();
tbxCustomerAddress.Text = pRow["CustomerAddress"].ToString();
tbxCustomerAge.Text = pRow["CustomerAge"].ToString();
}
}