Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

VB "System.Data.SqlDbType.Int" problem

  • 11-05-2008 10:46PM
    #1
    Closed Accounts Posts: 39


    Hi,

    Im kinda new to this whole programming thing, but i am getting a little trouble in one area. The Problem is where you see "System.Data.SqlDbType.Int", i think this is due to the fact i have changed the code here to work for an access db rather than sql server - but SqlDbType isnt valid. but ive been searching the net all day with no luck. any help would be greatley appreciated.


    Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" & Server.MapPath("~\db\digital.mdb")
    Dim Conn As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(ConnectionString)

    Dim comm As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand("INSERT INTO [SC2_tbl] ([UserID], [ProductID], [ProductName], [ImageS], [Date], [Price], [Quantity]) VALUES (@UserID, @ProductID, @ProductName, @ImageS, @Date, @Price, @Quantity)", Conn)

    comm.Parameters.Add("@UserID", System.Data.OleDb.NChar, 36)
    Comm.Parameters("@UserID").Value = Session("UserID") 'Set in Global.asax
    Comm.Parameters.Add("@ProductID", System.Data.SqlDbType.Int)
    Comm.Parameters("@ProductID").Value = ProductID
    Comm.Parameters.Add("@ProductName", System.Data.SqlDbType.VarChar, 50)
    Comm.Parameters("@ProductName").Value = ProductName
    Comm.Parameters.Add("@ImageS", System.Data.SqlDbType.VarChar, 50)
    Comm.Parameters("@ImageS").Value = ImageS
    Comm.Parameters.Add("@Date", System.Data.SqlDbType.SmallDateTime)
    Comm.Parameters("@Date").Value = SaleDate
    Comm.Parameters.Add("@Price", System.Data.SqlDbType.SmallMoney)
    Comm.Parameters("@Price").Value = Price
    Comm.Parameters.Add("@Quantity", System.Data.SqlDbType.Int)
    Comm.Parameters("@Quantity").Value = Quantity

    Try
    conn.Open()
    Comm.ExecuteNonQuery()
    Catch ex As Exception


Comments

  • Closed Accounts Posts: 413 ✭✭sobriquet


    What error are you getting? I assume it's an exception of some sort?

    For the UserID you use System.Data.OleDb.NChar - are there corresponding OleDb.whatever enumerations for other types? If so you might need to change all the subsequent SqlDbTypes to those.

    Yeah, quick google of OleDbType seems to confirm that that's what you'll want to use.


  • Closed Accounts Posts: 164 ✭✭ob


    You could use addwithvalue:


    Instead of this:

    comm.Parameters.Add("@UserID", System.Data.OleDb.NChar, 36)
    comm.Parameters("@UserID").Value = Session("UserID") 'Set in Global.asax

    Try this:

    comm.Parameters.AddWithValue("@UserID", Session("UserID"))


Advertisement