Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > syntax problem (vb) data connection

Reply
Thread Tools

syntax problem (vb) data connection

 
 
slinky
Guest
Posts: n/a
 
      08-10-2007
I'm making a OLE DB connection in code and was wondering if anyone
could identify what the syntax errors I have. I've tried countless
combinations and all give errors.

New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data & _
Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
"Initial Catalog=Assets;Integrated Security=SSPI")


Thanks!!

Below is my complete code:

Imports System.Data
Imports System.Data.OleDb
Public Class Default5
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim cnn As OleDbConnection = _
New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data & _
Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
"Initial Catalog=Assets;Integrated Security=SSPI")
Dim ds As DataSet = New DataSet()
Dim da As OleDbDataAdapter = New OleDbDataAdapter()
If Not IsPostBack Then
Dim cmdSelect As OleDbCommand = _
cnn.CreateCommand()
cmdSelect.CommandType = CommandType.Text
cmdSelect.CommandText = _
"SELECT ([Asset Number], Description, [Serial Number], Mfg,
AssetType,
RDCnumber) FROM Assets"
Dim cmdInsert As OleDbCommand = _
cnn.CreateCommand()
cmdInsert.CommandType = CommandType.Text
cmdInsert.CommandText = _
"INSERT INTO Assets " & _
"([Asset Number], Description, [Serial Number], Mfg, AssetType,
RDCnumber) " & _
"VALUES(@AssetNumber, @Description, @Serial_Number, @Mfg, @AssetType,
@RDCnumber"
cmdInsert.Parameters.Add("@txtAsset_Number",
OleDbType.Double, 12, "[Asset Number]")
cmdInsert.Parameters.Add("@txtDescription",
OleDbType.WChar, 40, "Description")
cmdInsert.Parameters.Add("@txtSerial_Number",
OleDbType.WChar, 30, "[Serial Number]")
cmdInsert.Parameters.Add("@txtMfg", OleDbType.WChar, 30,
"Mfg")
cmdInsert.Parameters.Add("@txtAssetType",
OleDbType.WChar,
30, "AssetType")
cmdInsert.Parameters.Add("@txtRDCNumber",
OleDbType.WChar,
30, "RDCnumber")
Dim SourceVersion As DataRowVersion
SourceVersion = DataRowVersion.Original
da.SelectCommand = cmdSelect
da.InsertCommand = cmdInsert
da.Fill(ds, "Assets")
End If
End Sub
Private Sub btnAdd_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnAdd.Click
Dim cnn As OleDbConnection = _
New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data & _
Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
"Initial Catalog=Assets;Integrated Security=SSPI")
Dim ds As DataSet = New DataSet()
Dim da As OleDbDataAdapter = New OleDbDataAdapter()
Dim dr As DataRow = ds.Tables("Assets").NewRow()
dr(0) = txtAsset_Number.Text
dr(1) = txtDescription.Text
dr(2) = txtSerial_Number.Text
dr(3) = txtMfg.Text
dr(4) = txtAssetType.Text
dr(5) = txtRDCnumber.Text
ds.Tables("Assets").Rows.Add(dr)
da.Update(ds, "Assets")
End Sub
End Class

 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      08-10-2007
On Aug 10, 2:50 pm, slinky <campbellbrian2...@yahoo.com> wrote:
> I'm making a OLE DB connection in code and was wondering if anyone
> could identify what the syntax errors I have. I've tried countless
> combinations and all give errors.
>
> New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data & _
> Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
> "Initial Catalog=Assets;Integrated Security=SSPI")
>
> Thanks!!
>
> Below is my complete code:
>
> Imports System.Data
> Imports System.Data.OleDb
> Public Class Default5
> Inherits System.Web.UI.Page
> Private Sub Page_Load(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> Dim cnn As OleDbConnection = _
> New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data & _
> Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
> "Initial Catalog=Assets;Integrated Security=SSPI")
> Dim ds As DataSet = New DataSet()
> Dim da As OleDbDataAdapter = New OleDbDataAdapter()
> If Not IsPostBack Then
> Dim cmdSelect As OleDbCommand = _
> cnn.CreateCommand()
> cmdSelect.CommandType = CommandType.Text
> cmdSelect.CommandText = _
> "SELECT ([Asset Number], Description, [Serial Number], Mfg,
> AssetType,
> RDCnumber) FROM Assets"
> Dim cmdInsert As OleDbCommand = _
> cnn.CreateCommand()
> cmdInsert.CommandType = CommandType.Text
> cmdInsert.CommandText = _
> "INSERT INTO Assets " & _
> "([Asset Number], Description, [Serial Number], Mfg, AssetType,
> RDCnumber) " & _
> "VALUES(@AssetNumber, @Description, @Serial_Number, @Mfg, @AssetType,
> @RDCnumber"
> cmdInsert.Parameters.Add("@txtAsset_Number",
> OleDbType.Double, 12, "[Asset Number]")
> cmdInsert.Parameters.Add("@txtDescription",
> OleDbType.WChar, 40, "Description")
> cmdInsert.Parameters.Add("@txtSerial_Number",
> OleDbType.WChar, 30, "[Serial Number]")
> cmdInsert.Parameters.Add("@txtMfg", OleDbType.WChar, 30,
> "Mfg")
> cmdInsert.Parameters.Add("@txtAssetType",
> OleDbType.WChar,
> 30, "AssetType")
> cmdInsert.Parameters.Add("@txtRDCNumber",
> OleDbType.WChar,
> 30, "RDCnumber")
> Dim SourceVersion As DataRowVersion
> SourceVersion = DataRowVersion.Original
> da.SelectCommand = cmdSelect
> da.InsertCommand = cmdInsert
> da.Fill(ds, "Assets")
> End If
> End Sub
> Private Sub btnAdd_Click( _
> ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles btnAdd.Click
> Dim cnn As OleDbConnection = _
> New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data & _
> Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
> "Initial Catalog=Assets;Integrated Security=SSPI")
> Dim ds As DataSet = New DataSet()
> Dim da As OleDbDataAdapter = New OleDbDataAdapter()
> Dim dr As DataRow = ds.Tables("Assets").NewRow()
> dr(0) = txtAsset_Number.Text
> dr(1) = txtDescription.Text
> dr(2) = txtSerial_Number.Text
> dr(3) = txtMfg.Text
> dr(4) = txtAssetType.Text
> dr(5) = txtRDCnumber.Text
> ds.Tables("Assets").Rows.Add(dr)
> da.Update(ds, "Assets")
> End Sub
> End Class


A quotation mark is missing at the first line

New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data (HERE) &
_
Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
"Initial Catalog=Assets;Integrated Security=SSPI")

 
Reply With Quote
 
 
 
 
slinky
Guest
Posts: n/a
 
      08-10-2007
I used this:

New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data" &
_
Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
"Initial Catalog=Assets;Integrated Security=SSPI")

But now the bottom line lists syntax errors: "Initial
Catalog=Assets;Integrated Security=SSPI"

Plus the "~" is still being listed as a Not Valid Character.



On Aug 10, 10:19 am, Alexey Smirnov <alexey.smir...@gmail.com> wrote:
> On Aug 10, 2:50 pm, slinky <campbellbrian2...@yahoo.com> wrote:
>
>
>
>
>
> > I'm making a OLE DB connection in code and was wondering if anyone
> > could identify what the syntax errors I have. I've tried countless
> > combinations and all give errors.

>
> > New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data & _
> > Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
> > "Initial Catalog=Assets;Integrated Security=SSPI")

>
> > Thanks!!

>
> > Below is my complete code:

>
> > Imports System.Data
> > Imports System.Data.OleDb
> > Public Class Default5
> > Inherits System.Web.UI.Page
> > Private Sub Page_Load(ByVal sender As System.Object, _
> > ByVal e As System.EventArgs) Handles MyBase.Load
> > Dim cnn As OleDbConnection = _
> > New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data & _
> > Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
> > "Initial Catalog=Assets;Integrated Security=SSPI")
> > Dim ds As DataSet = New DataSet()
> > Dim da As OleDbDataAdapter = New OleDbDataAdapter()
> > If Not IsPostBack Then
> > Dim cmdSelect As OleDbCommand = _
> > cnn.CreateCommand()
> > cmdSelect.CommandType = CommandType.Text
> > cmdSelect.CommandText = _
> > "SELECT ([Asset Number], Description, [Serial Number], Mfg,
> > AssetType,
> > RDCnumber) FROM Assets"
> > Dim cmdInsert As OleDbCommand = _
> > cnn.CreateCommand()
> > cmdInsert.CommandType = CommandType.Text
> > cmdInsert.CommandText = _
> > "INSERT INTO Assets " & _
> > "([Asset Number], Description, [Serial Number], Mfg, AssetType,
> > RDCnumber) " & _
> > "VALUES(@AssetNumber, @Description, @Serial_Number, @Mfg, @AssetType,
> > @RDCnumber"
> > cmdInsert.Parameters.Add("@txtAsset_Number",
> > OleDbType.Double, 12, "[Asset Number]")
> > cmdInsert.Parameters.Add("@txtDescription",
> > OleDbType.WChar, 40, "Description")
> > cmdInsert.Parameters.Add("@txtSerial_Number",
> > OleDbType.WChar, 30, "[Serial Number]")
> > cmdInsert.Parameters.Add("@txtMfg", OleDbType.WChar, 30,
> > "Mfg")
> > cmdInsert.Parameters.Add("@txtAssetType",
> > OleDbType.WChar,
> > 30, "AssetType")
> > cmdInsert.Parameters.Add("@txtRDCNumber",
> > OleDbType.WChar,
> > 30, "RDCnumber")
> > Dim SourceVersion As DataRowVersion
> > SourceVersion = DataRowVersion.Original
> > da.SelectCommand = cmdSelect
> > da.InsertCommand = cmdInsert
> > da.Fill(ds, "Assets")
> > End If
> > End Sub
> > Private Sub btnAdd_Click( _
> > ByVal sender As System.Object, _
> > ByVal e As System.EventArgs) Handles btnAdd.Click
> > Dim cnn As OleDbConnection = _
> > New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data & _
> > Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
> > "Initial Catalog=Assets;Integrated Security=SSPI")
> > Dim ds As DataSet = New DataSet()
> > Dim da As OleDbDataAdapter = New OleDbDataAdapter()
> > Dim dr As DataRow = ds.Tables("Assets").NewRow()
> > dr(0) = txtAsset_Number.Text
> > dr(1) = txtDescription.Text
> > dr(2) = txtSerial_Number.Text
> > dr(3) = txtMfg.Text
> > dr(4) = txtAssetType.Text
> > dr(5) = txtRDCnumber.Text
> > ds.Tables("Assets").Rows.Add(dr)
> > da.Update(ds, "Assets")
> > End Sub
> > End Class

>
> A quotation mark is missing at the first line
>
> New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data (HERE) &
> _
> Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
> "Initial Catalog=Assets;Integrated Security=SSPI")- Hide quoted text -
>
> - Show quoted text -



 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      08-10-2007
On Aug 10, 4:56 pm, slinky <campbellbrian2...@yahoo.com> wrote:
> I used this:
>
> New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data" &
> _
> Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
> "Initial Catalog=Assets;Integrated Security=SSPI")
>
> But now the bottom line lists syntax errors: "Initial
> Catalog=Assets;Integrated Security=SSPI"
>
> Plus the "~" is still being listed as a Not Valid Character.
>


Ignore extra breaks that google groups does in the code

Go to your original message and add just one (") at the end of the
first line

A long string in VB must be concatenated with & and _

For example:

"........." & "........." & _
".........." _
& "......"

 
Reply With Quote
 
slinky
Guest
Posts: n/a
 
      08-10-2007
Thanks Alexey.. that got rid of all the errors in the .aspx.vb file,
but when I launch the .aspx file in the browser I get this error as
before with line 34 of the .aspx.vb highlighted in red as the
problem: Line 34: da.Fill(ds, "Assets")

Server Error in '/' Application.
--------------------------------------------------------------------------------

Multiple-step OLE DB operation generated errors. Check each OLE DB
status value, if available. No work was done.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Multiple-step OLE
DB operation generated errors. Check each OLE DB status value, if
available. No work was done.

Source Error:


Line 32: da.SelectCommand = cmdSelect
Line 33: da.InsertCommand = cmdInsert
Line 34: da.Fill(ds, "Assets")
Line 35: End If
Line 36: End Sub


Source File: E:\kunden\homepages\26\d190091667\Default5.aspx.vb
Line: 34

Stack Trace:


[OleDbException (0x80040e21): Multiple-step OLE DB operation generated
errors. Check each OLE DB status value, if available. No work was
done.]

System.Data.OleDb.OleDbServicesWrapper.GetDataSour ce(OleDbConnectionString
constr, DataSourceWrapper& datasrcWrapper) +209

System.Data.OleDb.OleDbConnectionInternal..ctor(Ol eDbConnectionString
constr, OleDbConnection connection) +118

System.Data.OleDb.OleDbConnectionFactory.CreateCon nection(DbConnectionOptions
options, Object poolGroupProviderInfo, DbConnectionPool pool,
DbConnection owningObject) +53

System.Data.ProviderBase.DbConnectionFactory.Creat eNonPooledConnection(DbConnection
owningConnection, DbConnectionPoolGroup poolGroup) +27

System.Data.ProviderBase.DbConnectionFactory.GetCo nnection(DbConnection
owningConnection) +47

System.Data.ProviderBase.DbConnectionClosed.OpenCo nnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.OleDb.OleDbConnection.Open() +37
System.Data.Common.DbDataAdapter.FillInternal(Data Set dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior) +121
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior) +137
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
srcTable) +83
Default5.Page_Load(Object sender, EventArgs e) in E:\kunden
\homepages\26\d190091667\Default5.aspx.vb:34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1061




On Aug 10, 11:08 am, Alexey Smirnov <alexey.smir...@gmail.com> wrote:
> On Aug 10, 4:56 pm, slinky <campbellbrian2...@yahoo.com> wrote:
>
> > I used this:

>
> > New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data" &
> > _
> > Source=" & Server.MapPath("~/App_Data/Lowes.mdb") & ";" & _
> > "Initial Catalog=Assets;Integrated Security=SSPI")

>
> > But now the bottom line lists syntax errors: "Initial
> > Catalog=Assets;Integrated Security=SSPI"

>
> > Plus the "~" is still being listed as a Not Valid Character.

>
> Ignore extra breaks that google groups does in the code
>
> Go to your original message and add just one (") at the end of the
> first line
>
> A long string in VB must be concatenated with & and _
>
> For example:
>
> "........." & "........." & _
> ".........." _
> & "......"



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Checker that's better than the normal syntax checker Jacob Grover Ruby 5 07-18-2008 05:07 AM
Syntax error? What syntax error? Assignment fo default values? Mark Richards Perl Misc 3 11-18-2007 05:01 PM
Syntax bug, in 1.8.5? return not (some expr) <-- syntax error vsreturn (not (some expr)) <-- fine Good Night Moon Ruby 9 07-25-2007 04:51 PM
[ANN] SqlStatement 1.0.0 - hide the syntax of SQL behind familiarruby syntax Ken Bloom Ruby 3 10-09-2006 06:46 PM
Syntax highligth with textile: Syntax+RedCloth ? gabriele renzi Ruby 2 12-31-2005 02:44 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57