473,390 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

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 13400
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

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

Similar topics

0
by: Jon Moldover | last post by:
Hi, I'm using Python in my win32 app by linking to the python23.dll. I'm trying to expose some c++ code in my app to Python so I can make application calls from Python scripts (according to the...
2
by: attitude | last post by:
I've recently taken over a developer's project. She created a .NET web app in VB.NET and SQL Server 2000. The project is up and running fine. But i see one problem. I can't find the database the...
3
by: Bob | last post by:
I haver a user login form (winforms app using vs2005 in VB.NET). After succesfull validayion of user I want to open a first form and close the loging form that was used, If I write If...
5
by: Macca | last post by:
Hi, I have a multithreaded app which now needs database storage. I am in the process of designing my Data Access Layer but and was wondering what issues I should look for for in regards to a...
0
neo008
by: neo008 | last post by:
Hi All, I'm very new to .NET and want some help regarding database accessibility. I know about VB 6 but how database operations are performed in .NET, I have no idea. I have created...
18
by: waterfall | last post by:
How to get data from database in text box on selecting a value from combobox in C# web forms? Im using two tables employee and worker table.i succeeded in populating combobox with data from SQL...
3
by: manius | last post by:
im prety new so hope u will be patient. My questione is how to insert DataGridViewCheckBoxColumn value into access database. when i go like DataGridViewCheckBoxColumn.toString it seems does not...
2
by: senthilnova | last post by:
hi i have a form with First,Next,Prev,Buttons. i had populated a datatable with datas .Now i need to navigate through the records , can any body help me how to achieve this. ...
0
by: wahyuhid2384 | last post by:
Hi all.. I am creating a small application that supposed to monitor printing activities. I used Win32_PrintJob and successfully get the informations of printing process such as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.