Click here to Skip to main content
15,917,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends

I want to shwo value from database to text box through c# code(dataset). can u please help me to retreve data from sql to text box.
Posted

You can get the data by using this:

C#
DataTable t = new DataTable();
 using (SqlConnection c = new SqlConnection("pass  your connection string here"))
 {
   c.Open();
   using (SqlDataAdapter a = new SqlDataAdapter("Pass your Query Here", c))
    {
                    a.Fill(t);
    }
  }


You can attach the data to the textbox by using this:
textBox1.Text=t.Rows[0][0].ToString();
 
Share this answer
 
Hi,
Try this-

C#
private DataTable GetCurrentMembers()
{

AppSQL app1 = new AppSQL(System.Configuration.ConnectionStrings["MyconnectionString"].ConnectionString);string SqlText = @"
select count(*) from member

where activemembers = 0 and pID = " + _pid

DataSet ds = new DataSet();
app1.FillDataSet(ds);

return ds.Tables[0];

}

and then :

C#
myTextBox.Text = GetCurrentMembers().Rows[0][0].ToString();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900