how can i pass a database value to a textbox if i click a button.. should i use a query statement..? what kind? help pls ...

Recommended Answers

All 2 Replies

Set up your connection to the database and a command object with your SQL statement in it. Execute the command on the database, storing the result in a string, and then set the text box.text to the extracted value. So, pseudo code (assuming mySql):

MySqlConnection conn = new MySqlConnection(/connection string/);
MySqlCommand cmd = new mySqlCommand();
cmd.Connection = conn;
cmd.CommandText = your sql statement
conn.Open()
MySqlDataReader dr = cmd.executeReader();
conn.Close();
if(dr.hasRows) {
while(dr.Read()) {
    textbox.text = dr.getString(0);
}
}

And that should do it for you.

thanks for the help.. i will try that :D

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.