C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

retreiving data into winform textboxes during form load


Posted Date: 26 Sep 2008      Posted By: CRPRAJAN      Member Level: Gold     Points: 1   Responses: 2



I have two fields in my C# winform where the first record from the sql server table should get displayed. What is the code?

Thanx in advance





Responses

Author: Anil Kumar Pandey    26 Sep 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 5

hi,

please refer the following code..

Dim con As New SqlConnection(conString)
Dim cmd As SqlCommand
Dim query As String

query = "SELECT Proj_ID, Proj_Name FROM Projects"
Dim da As New SqlDataAdapter(query, con)
Dim ds As New DataSet

da.Fill(ds, "Projects")
da.Dispose()

Textbox1.Text = ds.Tables[0].Rows[0]["Proj_Name"].Tostring();
Textbox2.Text = ds.Tables[0].Rows[0]["Proj_Id"].Tostring();





Regards
Anil

Thanks & Regards
Anil Kumar Pandey



Author: Avadhesh Kumar Tiwari    26 Sep 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 5

try


using System.data.SqlClient;

sqlconnection con;
sqlcommand com;
sqldataadapter da
dataset ds;


at Form_Load event

{

con=new sqlconnection("Data Source=servername;Initial Catalog=db_name;User ID=sa;Password=sa");
com=new sqlcommand("Select emp_name from Employee",con);
da=new sqldataadapter(com);
da.fill(ds);

texBox.Text=ds.tables[0].Rows[0][0].ToString();

hope it will help You.....

You can contact me personally in avadhesh_fetcse@yahoomail.com or directally call me @ +919019548045



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Crystal reports
Previous : interface
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use