
December 29th, 2001, 09:32 AM
|
|
Contributing User
|
|
Join Date: Dec 2002
Posts: 14,575
  
Time spent in forums: < 1 sec
Reputation Power: 22
|
|
|
Originally posted by : bugeye------------Karen at 11/27/2001 9:00:31 PMCan someone please teach me how to connect to a SQL database using .NET?How to access its data??Hi Karen,Sorry hit enter...he heYou can use the following to connect to SQL data source:Sub Page_load( s As Object, e As EventArgs )Dim myConnetion As SqlConnectionDim myCommand As SqlCommandmyConnection = New SqlConnection( "Server=(yourserver);uid=(yourusername);pwd=(yourpa ssword);Database=(yourdatabase)")myCommand = New SqlConnamd( "your query logic goes here: ie) "Select * FROM pubs WHERE author = smith", myConnection)'open the connectionmyConnection.open()'stuff query into a dataGridmyDataGrid.DataSource = myCommand.ExecuteReader()myDataGrid.DataBind()'Clo se data connectionmyConnection.close()End SubThen you can display your records with following code:That should do it.
|