.aspx.vb code syntax

Discussion in 'ASP .Net' started by slinky, Aug 9, 2007.

  1. slinky

    slinky Guest

    I'm making a OLE DB connection in code and was wondering if anyone
    could identify what the syntax errors would be in this just as it is
    pasted (I tried putting & _ at the end of the first line and that
    only brought up other errors):

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

    Thanks!!
     
    slinky, Aug 9, 2007
    #1
    1. Advertising

  2. Have you looked at connectionstrings.com? Its a good url to bookmark.
    Peter
    --
    Recursion: see Recursion
    site: http://www.eggheadcafe.com
    unBlog: http://petesbloggerama.blogspot.com
    BlogMetaFinder: http://www.blogmetafinder.com



    "slinky" wrote:

    > I'm making a OLE DB connection in code and was wondering if anyone
    > could identify what the syntax errors would be in this just as it is
    > pasted (I tried putting & _ at the end of the first line and that
    > only brought up other errors):
    >
    > New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=" & Server.MapPath(~/App_Data/Lowes.mdb) & ";" & _
    > "Initial Catalog=Assets;Integrated Security=SSPI")
    >
    > Thanks!!
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Aug 9, 2007
    #2
    1. Advertising

  3. slinky

    slinky Guest

    I looked on connectionstrings.com but it did not have specifics for
    what could be wrong with the syntax... thanks though

    On Aug 9, 11:20 am, Peter Bromberg [C# MVP]
    <> wrote:
    > Have you looked at connectionstrings.com? Its a good url to bookmark.
    > Peter
    > --
    > Recursion: see Recursion
    > site: http://www.eggheadcafe.com
    > unBlog: http://petesbloggerama.blogspot.com
    > BlogMetaFinder: http://www.blogmetafinder.com
    >
    >
    >
    > "slinky" wrote:
    > > I'm making a OLE DB connection in code and was wondering if anyone
    > > could identify what the syntax errors would be in this just as it is
    > > pasted (I tried putting & _ at the end of the first line and that
    > > only brought up other errors):

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

    >
    > > Thanks!!- Hide quoted text -

    >
    > - Show quoted text -
     
    slinky, Aug 9, 2007
    #3
  4. slinky

    David Wier Guest

    try removing all continuation characters and see if it all works

    David Wier
    http://aspnet101.com
    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup



    "slinky" <> wrote in message
    news:...
    > I'm making a OLE DB connection in code and was wondering if anyone
    > could identify what the syntax errors would be in this just as it is
    > pasted (I tried putting & _ at the end of the first line and that
    > only brought up other errors):
    >
    > New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=" & Server.MapPath(~/App_Data/Lowes.mdb) & ";" & _
    > "Initial Catalog=Assets;Integrated Security=SSPI")
    >
    > Thanks!!
    >
     
    David Wier, Aug 9, 2007
    #4
  5. slinky

    slinky Guest

    I just did that with this line:

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

    I used no continuity characters and the line showed no errors, except
    one - it noted the ~ symbol as being not valid, but then errors showed
    up in other unexpected places like: 'cnn' is not declared... when my
    code (in its entirety below) shows that it IS declared.
    _________________________________________________________________________________

    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
    ______________________________________________________________________________________________________




    On Aug 9, 12:25 pm, "David Wier" <>
    wrote:
    > try removing all continuation characters and see if it all works
    >
    > David Wierhttp://aspnet101.comhttp://iWritePro.com- One click PDF, convert .doc/.rtf/.txt to HTML with no
    > bloated markup
    >
    > "slinky" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > I'm making a OLE DB connection in code and was wondering if anyone
    > > could identify what the syntax errors would be in this just as it is
    > > pasted (I tried putting & _ at the end of the first line and that
    > > only brought up other errors):

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

    >
    > > Thanks!!- Hide quoted text -

    >
    > - Show quoted text -
     
    slinky, Aug 9, 2007
    #5
  6. On Aug 9, 7:33 pm, slinky <> wrote:
    > I just did that with this line:
    >
    > New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    > Server.MapPath(~/App_Data/Lowes.mdb) " &";""Initial
    > Catalog=Assets;Integrated Security=SSPI")


    I guess

    Server.MapPath("~/App_Data/Lowes.mdb")
     
    Alexey Smirnov, Aug 9, 2007
    #6
  7. On Aug 9, 7:39 pm, Alexey Smirnov <> wrote:
    > On Aug 9, 7:33 pm, slinky <> wrote:
    >
    > > I just did that with this line:

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

    >
    > I guess
    >
    > Server.MapPath("~/App_Data/Lowes.mdb")


    and finally

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

    you should understand that the goal of that concatenation is to have a
    properly formatted string, for example:

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\InetPub\wwwroot
    \App_Data\Lowes.mdb;Initial Catalog=Assets;Integrated Security=SSPI
     
    Alexey Smirnov, Aug 9, 2007
    #7
  8. slinky

    slinky Guest

    So would this work? I added a couple of continuity characters. Looks
    OK but it still doesn't allow the ~ symbol AND it still says the cnn's
    are not declared.

    New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    _
    Server.MapPath(~/App_Data/Lowes.mdb) " &";Initial & _
    Catalog=Assets;Integrated Security=SSPI")
     
    slinky, Aug 9, 2007
    #8
  9. On Aug 9, 8:13 pm, slinky <> wrote:
    > So would this work? I added a couple of continuity characters. Looks
    > OK but it still doesn't allow the ~ symbol AND it still says the cnn's
    > are not declared.
    >
    > New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    > _
    > Server.MapPath(~/App_Data/Lowes.mdb) " &";Initial & _
    > Catalog=Assets;Integrated Security=SSPI")


    oh, sorry a silly copy typo:

    Server.MapPath("~/App_Data/Lowes.mdb")
     
    Alexey Smirnov, Aug 9, 2007
    #9
  10. slinky

    slinky Guest

    OK I put this in:

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

    But then the " &" part of the second line errors
    with: "Comma, ")", or valid expression expected"

    Plus any clues as to why the 'cnn' isn't recognized?

    On Aug 9, 2:21 pm, Alexey Smirnov <> wrote:
    > On Aug 9, 8:13 pm, slinky <> wrote:
    >
    > > So would this work? I added a couple of continuity characters. Looks
    > > OK but it still doesn't allow the ~ symbol AND it still says the cnn's
    > > are not declared.

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

    >
    > oh, sorry a silly copy typo:
    >
    > Server.MapPath("~/App_Data/Lowes.mdb")
     
    slinky, Aug 9, 2007
    #10
  11. Instead of

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


    Try this:

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


    Akin
    --
    akyak at aksoto dot idps dot co dot uk
     
    Silicon Strawberry, Aug 10, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paolo Pignatelli
    Replies:
    6
    Views:
    2,236
    Paolo Pignatelli
    Feb 21, 2005
  2. John M
    Replies:
    1
    Views:
    1,310
    Kumar Reddi
    May 29, 2005
  3. MadHatter51
    Replies:
    1
    Views:
    908
    Hakan Lambracht
    May 17, 2006
  4. Mr Flibble
    Replies:
    8
    Views:
    38,591
    Will Asrari
    May 23, 2006
  5. RadioSignal

    passing variables from .aspx.cs code pages to .aspx pages

    RadioSignal, Sep 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    7
    Views:
    2,389
    Mirronelli
    Oct 22, 2005
Loading...

Share This Page