7 Feb 2014

How to bind dataset value to textbox in c# (or) how to assign value from dataset to dataset in c# asp.net

This post shows how to assign dataset values into Textboxes or labels , how to get row value from dataset in c#,   Get a single value from dataSet in asp.net



 protected void btnsearch_Click(object sender, EventArgs e)
        {
            if (Label2.Text != "" && Session["username"].ToString() != "")
            {
                 string un = Convert.ToString(Session["username"]);
                string nameproof ="select * from UserRegistration where UEmail = '"+ un +"'";

// here con is your connection string

                SqlDataAdapter ad = new SqlDataAdapter(nameproof,con);
                DataSet ds = new DataSet();
                ad.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    string uname = ds.Tables[0].Rows[0]["UName"].ToString();
                    string proof1 = ds.Tables[0].Rows[0]["UIdproof"].ToString();
                    string proof2 = ds.Tables[0].Rows[0]["UIdnumber"].ToString();
                    string proof = proof1 + proof2;
                   
                }
            }
        }


1 comment: