Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two table in sql 2008 and i have one project i made the front page of my project in VB.Net and i made that two table in SQL2008 now i have problem with connection between SQL table and VB.Net.

I don't know how to connect the Tables with VB.Net

Can you please help to guide that how can i solve this problem.


Thanks

Amin
Posted

I would say that you should get hold of a good book on basic VB.Net and study up on ADO.Net using SQLConnection, SQLCommand, SQLDataReader etc methods.

Happy Learning
 
Share this answer
 
Read about ADO.NET and it will help you.

Look at these:
MSDN: ADO.NET [^]
Using DataReaders, SQL Server [^]
The C# Station ADO.NET Tutorial[^]
 
Share this answer
 
Please follow the below steps

1. If the database name is : NorthWindDB.

2. in web.config file add the following code.

<connectionString>

<add name="NorthWindDB" value="Server=machinename\SQLEXPRESS;Database=NorthWindDB;User Id=sa;password=dss;" />
</connectionString>


3. In the code file, import the following namespaces.

Imports System.Data;
Imports System,Data.SqlClient;


4. Add the reference to System.Configuration namespace. By right clicking the project-> click Add Reference -> select System.Configuration -> ok.

Write the following code to connect to the database and execute the query "select * from Emp". This query retreives all the rows from the Emp table of the NorthWindDB database.

5.Dim con as New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("NorthWindDB").ConnectionString()

dim cmd as New SqlCommand(con,"select * from Emp")

dim dr as SqlDataReader = cmd.ExecuteReader()

while(dr.Read())

//Process the data as per your requirement.

End While

<a href="http://dotnetforbeginner.blogspot.com/">http://dotnetforbeginner.blogspot.com/</a><a href="http://dotnetforbeginner.blogspot.com/" target="_blank" title="New Window"></a>
 
Share this answer
 
v3
You'll need to read up on connection strings / and the system.data.sql namespace

start by reading some of the links in this search:

http://www.google.co.uk/search?hl=en&q=sql+connection+%2B+vb.net&meta=[^]

and if for the right connection string go to
http://www.connectionstrings.com/[^]
 
Share this answer
 
first implement this:

Imports System.Data
Imports System.Data.SqlClient


second:
Sub SQLConnect()
Dim connStr As String = "Data Source=.\sqlexpress;initial Catalog=DataBaseName;integrated security=true"
Dim sqlConn As New SqlConnection(connStr)
sqlConn.Open() 'Connecting Successful
'Working Online
Dim cmd As New SqlCommand
cmd.Connection = sqlConn
cmd.CommandText = "select Col1,Col2 from Table1"
Dim sqlread As SqlDataReader = cmd.ExecuteReader 'Retreiving Multi Rows from table
'Working Offline
Dim sqlAda As New SqlDataAdapter("select Col1,Col2 from Table1", connStr)
Dim ds As New DataSet
sqlAda.Fill(ds, "Table1") ' Fill All Data resulting in sql query in data set object and can use it after closing connection
sqlConn.Close() 'Now Can working onle with offline mode
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900