Form Population from another Form [Newbie Question]
Hello All.
First thank you for reading.
I am trying to learn c# and due to unemployment am scouring the internet for free resources to do so. I have come across videos and ebook's and now this website.
after beginning my debut programme (a simple address book) I'm stuck...
I have managed to create a very nice UI (easy in VS08) and a database. on the first form it lists the names in the database in a listbox. When a name is double clicked it opens a dialog box instance of a details page.
I have managed to grab the ID from the name clicked and throw it at the details form,
The 2nd form takes this ID and displays it in a text box, But all the other components of the form show details of another entry in the table...
I am using ADO.net, TableAdapters, BindingSource and Datasets. I have very limited understanding of these, but I thought Binding source was meant to update all fields to represent the same record (row, entry) ?
So my question is, What am I missing to make this happen?
~Ore P.S For somereason all formatting I try and acheive in this forum is futile. It might be my browser settings. I have code I was going to post but since my formatting is buggered it would have just complicated things.
Gautam BaruahPosted Nov 16, 2009, 4:05 PM
string sql="select * from tableName where id='"+id+"'"
sqlconnection cn=new sqlconnection(your ConnectionString)
SqlCommand cmd=new Sqlcommand(sql,cn);
cn.open()
SqlDataReader reader=cmd.ExecuteReader();
if(reader.reader())
{
textBox1=reader["id"].toString()
textBox2=reader["address"].toString();
// more values
}
reader.close();
cn.close();
Like that you have to get the value from your database table. I am not mentioning the codes in details. I dont know if I am able to guide you or not. Plz let me know if this was your problem.
Gautam BaruahPosted Nov 16, 2009, 5:00 PM
Paul ChambersPosted Nov 16, 2009, 4:15 PM
Paul ChambersPosted Nov 16, 2009, 3:48 PM
Gautam BaruahPosted Nov 16, 2009, 3:14 PM
As per my understanding you are trying to display values in textboxes using sqldataadapter, if so then try SqlDataReader. SqlDataTable and DataSet are used to display values in control blocks like gridview or datagrid. I dont know if I am giving you correct direction or not. Plz tell me your problem in details.I will be really very happy to help you out.