2

Can anyone please tell me what i am doing wrong here? Very basic level of Visual Basic experience.

Im trying to retrieve the ORDERID, ORDERDATE and CUSTOMERID from the database provided and show them in a dataGridView?

Dim con1 As New OleDbConnection
con1.ConnectionString = _
"Provider=msdaora;Data Source=orabis;User Id=112221800;Password=112221800;"

'Dim con1 As New SqlConnection("Provider=msdaora;Data Source=orabis;User Id=112221800;Password=112221800;")
con1.Open()
Dim cmd1 As New SqlCommand("select ORDERID, ORDERDATE AND CUSTOMERID from CUSORDER", con1)

Dim ada1 As New SqlDataAdapter(cmd1)
Dim ds1 As New DataSet
ada1.Fill(ds1)
ViewDeliverys.DataGridView1.DataSource = ds1.Tables(0)

con1.Close()
1
  • Are you using Oracle? Add it as a tag (or confirm and I will) Commented Sep 8, 2014 at 0:46

2 Answers 2

1

You cannot use a OleDbConnection whith a SqlCommand(SQL-Server). Which rdbms are you using?

This works for SQL-Server:

Using con = New SqlConnection(connectionString)
    Using da = New SqlDataAdapter("SELECT ORDERID, ORDERDATE AND CUSTOMERID from CUSORDER", con)
        Dim table = New DataTable()
        da.Fill(table)
        ViewDeliverys.DataGridView1.DataSource = table
    End Using
End Using

Edit: Here's the OleDb version:

Using con = New OleDbConnection(connectionString)
    Using da = New OleDbDataAdapter("SELECT ORDERID, ORDERDATE AND CUSTOMERID from CUSORDER", con)
        Dim table = New DataTable()
        da.Fill(table)
        ViewDeliverys.DataGridView1.DataSource = table
    End Using
End Using
Sign up to request clarification or add additional context in comments.

9 Comments

Using An Oracle SQL Developer? So will need the oleDbConnection?
Dim con1 As New SqlConnection con1.ConnectionString = _ "Provider=msdaora;Data Source=orabis;User Id=112221800;Password=112221800;" con1.Open() Dim da As New SqlDataAdapter(cmd1) Dim ds1 As New DataSet Using con = New OleDbConnection(connectionString:=) Using da = New OleDbDataAdapter("SELECT ORDERID, ORDERDATE AND CUSTOMERID from CUSORDER", con) Dim table = New DataTable() da.Fill(table) ViewDeliverys.DataGridView1.DataSource = table End Using End Using
So this is the whole thing? Sorry im at a real beginner stage. Appreciate your help.
@112221: I've shown the complete code to get the data and use it as DataSource for a DataGridView. Note that it's not necessary to open/close a connection with DataAdapter.Fill.
AHHHHH!!!!! Still getting the provider error.. Thanks for your help, I'll try figure it out some how.
|
0

What Database are you using SQL Sever or MS Access? If you are uing SQL Server use SQL Connection then OleDBConnection on MS Access.

For the correct connection string check it on:

http://www.connectionstrings.com

Check also this tutorial from:

http://vb.net-informations.com/ado.net-dataproviders/ado.net-sqldataadapter

And also Replace your query from:

Dim cmd1 As New SqlCommand("select ORDERID, ORDERDATE AND CUSTOMERID from CUSORDER", con1)

where ORDERDATE AND CUSTOMERID will throws you an error

Change it to:

Dim cmd1 As New SqlCommand("select ORDERID, ORDERDATE,CUSTOMERID from CUSORDER", con1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.