469,306 Members | 1,578 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

C# App:how to fetch records from the database

35
hello,

Can u tell me how we can retrieve the records from the database.
Dec 15 '06 #1
13 13097
Expand|Select|Wrap|Line Numbers
  1. connection = new SqlConnection();
  2. connection.ConnectionString = "Persist Security Info=False;" +
  3.   "Integrated Security=SSPI;database=northwind;" +
  4.   "server=localhost;Connect Timeout=30";
  5. connection.Open();
  6. dataadapter = new SqlDataAdapter("select * from customers", connection);
  7. dataset = new DataSet();
  8. dataadapter.Fill(dataset, "table1");
  9. dataGrid1.DataSource = dataset;
  10. dataGrid1.DataMember = "table1";
Dec 15 '06 #2
muskan
35
Actually I want to know how we can fetch records from database into controls using dataadapter not execute reader command.
Dec 15 '06 #3
in the example i have provided it uses the dataadapter itself,
and datagrid is a control where the data is getting binded
Actually I want to know how we can fetch records from database into controls using dataadapter not execute reader command.
Dec 15 '06 #4
muskan
35
I want to put data into textboxes not datagrid
Dec 15 '06 #5
for a textbox i am sure that u wil not fetch more than one row of data
so,,..
Expand|Select|Wrap|Line Numbers
  1. connection = new SqlConnection();
  2. connection.ConnectionString = "Persist Security Info=False;" +
  3. "Integrated Security=SSPI;database=northwind;" +
  4. "server=localhost;Connect Timeout=30";
  5. connection.Open();
  6. dataadapter = new SqlDataAdapter("select * from customers", connection);
  7. dataset = new DataSet();
  8. dataadapter.Fill(dataset, "table1");
  9. //dataGrid1.DataSource = dataset;
  10. //so once ur dataset is filled then from that pick one value
  11. textbox1.text = dataset.tables("table1").columns("colname");
I want to put data into textboxes not datagrid
Dec 15 '06 #6
muskan
35
I have written like this but it shows column name into the textboxes.
means it is showing name & roll no in textboxes instead of data values.

txtname.Text =ds.Tables[0].Columns["name"].ToString() ;
txtroll.Text= ds.Tables[0].Columns["roll no"].ToString() ;
OR

txtname.Text =ds.Tables["deatail].Columns["name"].ToString() ;
txtroll.Text= ds.Tables["detail"].Columns["roll no"].ToString() ;
Dec 15 '06 #7
txtname.Text =ds.Tables[0].ds.Tables["details"].Rows[0]["name"].ToString() ;
txtname.Text =ds.Tables[0].ds.Tables["details"].Rows[0]["roll no"].ToString() ;


please specify the row no like zeroth ..

I have written like this but it shows column name into the textboxes.
means it is showing name & roll no in textboxes instead of data values.

txtname.Text =ds.Tables[0].Columns["name"].ToString() ;
txtroll.Text= ds.Tables[0].Columns["roll no"].ToString() ;
OR

txtname.Text =ds.Tables["deatail].Columns["name"].ToString() ;
txtroll.Text= ds.Tables["detail"].Columns["roll no"].ToString() ;
Dec 15 '06 #8
muskan
35
thanks ...........a lot

now it is working.

but we can see only one record at a time.
how we can see all records one by one.
Dec 15 '06 #9
to view the list u need to use the listbox / datagrid ,,, u can display all items inside the textbox using a comma seperator...
thanks ...........a lot

now it is working.

but we can see only one record at a time.
how we can see all records one by one.
Dec 15 '06 #10
childg
2
I tried the code above and it tells me that it can't connect to the server.

"An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections."

but i have my db local in the app_data folder.
Nov 26 '07 #11
Shashi Sadasivan
1,435 Expert 1GB
please refer to www.connectionstrings.com on how to create a connection string to your database (file / server based)
Nov 26 '07 #12
childg
2
edit: after like 2 hours of sitting debugging i figure out my select statement had a missing space between the quotes...gotta love those buggers.
Nov 27 '07 #13
I Have To Insert Data In Sql Server Through Textbox WHEN CLICK ON BUTTON In Database Connectivity Plz Help Me
Mar 19 '08 #14

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by attitude | last post: by
5 posts views Thread by Macca | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.