Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

VB "System.Data.SqlDbType.Int" problem

  • 11-05-2008 9: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