Question:
VB.NET 2005 Database connection to SQL Server?
Quasar
2007-04-30 13:47:25 UTC
previuosly at VB 6, i used to fill an ADODC1 with information from SQL server, and after doing so i can connect textboxes. this way i can add, delete, edit, etc. etc. NOW at VB 2005 i want to do the same. BUT HOW????? HELP ME PLEASE
Five answers:
Smutty
2007-04-30 16:18:18 UTC
It depends on what you want to accomplish. Here is a simple example that retrieves records from the Employees table in the sample Northwind DB.



Dim connection As New SqlConnection ( "server=.; database=Northwind; uid=sa; pwd=; " ) 'connection object instantiated

Dim SqlCmd As New SqlCommand( "Select * From Employees " , connection) 'command object instantiated



connection.Open()

Dim reader As SqlDataReader = SqlCmd. ExecuteReader()



While reader.Read()

'loop through recrods fetched

'do your stuff here

End While



reader.Close() 'close reader

connection.Close() 'close connection
nullgateway
2007-04-30 19:01:19 UTC
You should create a DAL (Data Access Layer) I assume that you already have your SQL database located in a folder called App_data.



The DAL will be placed in a new folder added to your site called App_Code. To this new folder add a new item and select dataset (extension is XSD). Give it a meaningful name like the name of your DB. follow the reset of the prompts to finish the wizard. You will now have bound your control to a DAL tableadapter



Double click the new dataset object to open it and you will be presented with a light gray blank screen area. Right click in this area and select Add >> TableAdapter.



You will create a table adapter which will connect to a specific table in your DB. You will follow the prompts and create a SELECT * query. This query will be used as the basis for creating not only the SELECT but INSERT and DELETE finctions.

Save the dataset



Now from your web form add you control and click on the small arrow in the upper right corner of the control. This will give you a menu from which you will select "Choose Data Source" and then select from the drop down.

You will be presented with yet another wizard to Choose a datasource type" Select the OBJECT datasource type and click next. The next screen will ask you to choose a business object fro the dropdown. This will have your table adapter you just created listed in the dropdown.
?
2016-05-17 15:36:06 UTC
Have you looked at the Configuration/Surface Area Config.? And make sure Named Pipes is enabled, as well as Shared Memory. I had this problem for a while. But it sounds like you're trying to connect remotely. If that's the case, you will enable "TCP/IP", and do "Server=*IP*, *Port*" as the connection string instead.
sinkablehail1978
2007-04-30 13:54:04 UTC
Use the SQL server connection tool. Drag and drop it and configure it to the server you want to pull data from. Then just set the datasource for your text boxes to the right SQL connection.
Master J
2007-04-30 13:53:10 UTC
The site has a good set of info on connecting to a MySQL Server via VB.NET 2005.



You may be able to use that info & go from there.



http://home.comcast.net/~mking56/MyODBC_TutorialWeb/myodbc_tutorial.htm


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...