المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : how to retrieve data from mysql database and display it into textbox in c#



C# Programming
03-20-2012, 11:25 AM
Hi,

I have this code below that is not working like i want it to and has no errors when i debug. I want it to display a member values in respective textboxes that are in a table called 'addpeople' by a click of a button AFTER i key in the member ID of a member.
Text boxes are like;
Title
member ID
First name
Last Name
Address 1
Address 2
....
...
...
Email..

Here is the code:

private void btnView_Click(object sender, EventArgs e) { string input = cmbMemberId.Text; string conn = "server=localhost;user=root;password='';database=m_chama;"; MySqlConnection myconn = new MySqlConnection(conn); string sql = "SELECT * FROM addmember WHERE Member_ID = '" + input + "';"; MySqlDataAdapter da = new MySqlDataAdapter(sql, myconn); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count == 0) { MessageBox.Show("No data found.", "Not Exists"); } else { foreach (DataRow dr in dt.Rows) { if (dr[0] + "" == input) { txtFirstName.Text = dr[0] + ""; break; } } } }

I will highly appreciate any help offered
Thanks

Xonel