Imports System.Data.OleDb
Public Class Cos
Inherits System.Web.UI.Page
Dim CosCumparaturi As New List(Of Produs)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
CosCumparaturi = Session("CC")
GridView1.DataSource = CosCumparaturi
GridView1.DataBind()
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myConn As OleDbConnection
Dim cmd As OleDbCommand
Dim CodProdus As Integer
Dim CantitateProdusVandut As Integer
Dim sqlString As String
Dim NrFacturaVanzare As Integer = 10001 'actually this is just so I can test this part, I must 'get it from another table
For Each Cos As Produs In CosCumparaturi
CodProdus = Cos.CodProdus
CantitateProdusVandut = Cos.Cantitate
myConn = New OleDbConnection("Provider = Microsoft.JET.OLEDB.4.0;DataSource=../Baza de Date/Magazin Virtual.accdb")
myConn.Open()
sqlString = "Insert into ProduseFacturateVandute (NrFacturaVanzare, CodProdus, CantitateProdusVandut) values ('" & NrFacturaVanzare & "','" & CodProdus & "','" & CantitateProdusVandut & "')"""
cmd = New OleDbCommand(sqlString, myConn)
cmd.ExecuteNonQuery()
myConn.Close()
Next
End Sub
End Class
And I get the error in this picture:
Can you please help me fix it?
I belive it's from this row, but don't know how to fix it:
myConn = New OleDbConnection("Provider = Microsoft.JET.OLEDB.4.0;DataSource=../Baza de Date/Magazin Virtual.accdb")
I think you are right about the line it is occurring on. It is probably an error in your connection string. I think you need a space in "DataSource" to be "Data Source".
myConn = New OleDbConnection("Provider = Microsoft.JET.OLEDB.4.0;Data Source=../Baza de Date/Magazin Virtual.accdb"
You may also need to double check the version of jet engine that you are specifying. Version 4.0 is for access 2000.
andreidragos...
Member
3 Points
24 Posts
Error at INSERT sql code...
Jul 06, 2012 04:53 PM|LINK
So... the VB.NET code is like this:
Imports System.Data.OleDb Public Class Cos Inherits System.Web.UI.Page Dim CosCumparaturi As New List(Of Produs) Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load CosCumparaturi = Session("CC") GridView1.DataSource = CosCumparaturi GridView1.DataBind() End Sub Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim myConn As OleDbConnection Dim cmd As OleDbCommand Dim CodProdus As Integer Dim CantitateProdusVandut As Integer Dim sqlString As String Dim NrFacturaVanzare As Integer = 10001 'actually this is just so I can test this part, I must 'get it from another table For Each Cos As Produs In CosCumparaturi CodProdus = Cos.CodProdus CantitateProdusVandut = Cos.Cantitate myConn = New OleDbConnection("Provider = Microsoft.JET.OLEDB.4.0;DataSource=../Baza de Date/Magazin Virtual.accdb") myConn.Open() sqlString = "Insert into ProduseFacturateVandute (NrFacturaVanzare, CodProdus, CantitateProdusVandut) values ('" & NrFacturaVanzare & "','" & CodProdus & "','" & CantitateProdusVandut & "')""" cmd = New OleDbCommand(sqlString, myConn) cmd.ExecuteNonQuery() myConn.Close() Next End Sub End ClassAnd I get the error in this picture:
Can you please help me fix it?
I belive it's from this row, but don't know how to fix it:
myConn = New OleDbConnection("Provider = Microsoft.JET.OLEDB.4.0;DataSource=../Baza de Date/Magazin Virtual.accdb")MattsDotNetU...
Contributor
3178 Points
515 Posts
Re: Error at INSERT sql code...
Jul 06, 2012 05:09 PM|LINK
I think you are right about the line it is occurring on. It is probably an error in your connection string. I think you need a space in "DataSource" to be "Data Source".
myConn = New OleDbConnection("Provider = Microsoft.JET.OLEDB.4.0;Data Source=../Baza de Date/Magazin Virtual.accdb"You may also need to double check the version of jet engine that you are specifying. Version 4.0 is for access 2000.
http://www.connectionstrings.com/access
If you are using a newer version you may need to use a newer ACE provider.
http://www.connectionstrings.com/access-2007
Rajneesh Ver...
All-Star
36945 Points
6779 Posts
Re: Error at INSERT sql code...
Jul 06, 2012 05:10 PM|LINK
Put single quote around the datasource:
myConn = New OleDbConnection("Provider = Microsoft.JET.OLEDB.4.0;Data Source='../Baza de Date/Magazin Virtual.accdb'")Check Connection strings:http://connectionstrings.com/access-2007www.rajneeshverma.com
Keep Forums Clean || Use Alert Moderators.
andreidragos...
Member
3 Points
24 Posts
Re: Error at INSERT sql code...
Jul 06, 2012 07:49 PM|LINK
Ok so I updated the connection, I didn't know the Provider... I didn't know the coding...
Now I get another error:
any ideeas on how to fix this? :-s
andreidragos...
Member
3 Points
24 Posts
Re: Error at INSERT sql code...
Jul 07, 2012 08:56 AM|LINK
Guess nobody can help me...
andreidragos...
Member
3 Points
24 Posts
Re: Error at INSERT sql code...
Jul 08, 2012 01:55 PM|LINK
The problem was at the path... I should have used:
myConn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & MapPath("~/Baza de date/Magazin Virtual.accdb"))