DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 1 of 1

Thread: Doesnt Insert

  1. #1
    Join Date
    Apr 2006
    Posts
    2

    Doesnt Insert

    I have created a form but it doesnt insert the fileds in the table :wacko:


    Code:
    sub btnSave_Click(sender As Object, e As EventArgs)
    
        Dim strAssetType As string = lstAssetType.SelectedIndex
        Dim TrackStatus As string = rbtnAssetType.SelectedIndex
        Dim Quantity As string = txtQuantity.Text
        Dim Name As string = txtName.Text
        Dim Description As string = txtDesc.Text
        Dim Status As string = selectStatus.SelectedIndex
    
    
       If lstAssetType.SelectedIndex  = 0 and rbtnAssetType.SelectedIndex = 0 and txtQuantity.Text = "" _
        and txtName.Text = "" and txtDesc.Text = "" and selectStatus.SelectedIndex = 0 Then
    
        lblMessage.Text = "Please Complete the form."
    
       ElseIF lstAssetType.SelectedIndex  <> "0" and rbtnAssetType.SelectedIndex <> "0" and txtQuantity.Text <> "" _
        and txtName.Text <> "" and txtDesc.Text <> "" and selectStatus.SelectedIndex <> "0" Then
    
        InsertNewItems(strassetType, trackStatus , name ,  description ,status ,quantity)
        lblMessage.Text = "You have submitted your form successfully"
    
    
       End if
    
    End Sub
    
    Sub rbtnAssetType_SelectedIndexChanged(sender As Object, e As EventArgs)
    
    Quantity()
    
    End Sub
    
    Private Sub Quantity()
    
    if rbtnAssetType.SelectedIndex = 2 Then
    Dim tblSerial as new table
    
    tblSerial.Enabled = false
    End if
    
    End Sub
    
    
    
        Function InsertNewItems(ByVal strassetType As String, ByVal trackStatus As String, ByVal name As String, ByVal description As String, ByVal status As String, ByVal quantity As Integer) As Integer
            Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=demo.mdb"
            Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
    
            Dim queryString As String = "INSERT INTO [tblNewItems] ([AssetType], [TrackStatus], [N"& _
                "ame], [Description], [Status], [Quantity]) VALUES (@AssetType, @TrackStatus, @Name, @Description, @Status, @Quantity)"
            Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
            dbCommand.CommandText = queryString
            dbCommand.Connection = dbConnection
            Dim dbParam_strassetType As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_strassetType.ParameterName = "@strassetType"
            dbParam_strassetType.Value = strassetType
            dbParam_strassetType.DbType = System.Data.DbType.[String]
            dbCommand.Parameters.Add(dbParam_strassetType)
            Dim dbParam_trackStatus As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_trackStatus.ParameterName = "@TrackStatus"
            dbParam_trackStatus.Value = trackStatus
            dbParam_trackStatus.DbType = System.Data.DbType.[String]
            dbCommand.Parameters.Add(dbParam_trackStatus)
            Dim dbParam_name As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_name.ParameterName = "@Name"
            dbParam_name.Value = name
            dbParam_name.DbType = System.Data.DbType.[String]
            dbCommand.Parameters.Add(dbParam_name)
            Dim dbParam_description As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_description.ParameterName = "@Description"
            dbParam_description.Value = description
            dbParam_description.DbType = System.Data.DbType.[String]
            dbCommand.Parameters.Add(dbParam_description)
            Dim dbParam_status As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_status.ParameterName = "@Status"
            dbParam_status.Value = status
            dbParam_status.DbType = System.Data.DbType.[String]
            dbCommand.Parameters.Add(dbParam_status)
            Dim dbParam_quantity As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_quantity.ParameterName = "@Quantity"
            dbParam_quantity.Value = quantity
            dbParam_quantity.DbType = System.Data.DbType.Int32
            dbCommand.Parameters.Add(dbParam_quantity)
    
            Dim rowsAffected As Integer = 0
            dbConnection.Open
            Try
                rowsAffected = dbCommand.ExecuteNonQuery
            Finally
                dbConnection.Close
            End Try
    
            Return rowsAffected
        End Function
    Attached is the database
    Attached Files

    Vision without action is a daydream. Action with without vision is a nightmare [[My Place]]

Similar Threads

  1. Re: Delay in Insert Trigger - My mistake !
    By Steve in forum Database
    Replies: 0
    Last Post: 02-19-2003, 04:51 AM
  2. Having issues with BULK INSERT, please advise...
    By Tony Fountain in forum Database
    Replies: 4
    Last Post: 02-04-2003, 04:30 PM
  3. INSERT for multiple tables with IDENTITY
    By Kay in forum Database
    Replies: 1
    Last Post: 07-04-2001, 05:18 AM
  4. SQL Tutorial (Answer Q's & post your reply)
    By bigbastard4 in forum Database
    Replies: 2
    Last Post: 05-16-2001, 06:24 PM
  5. Insert with no columns?
    By Colin McGuigan in forum Database
    Replies: 5
    Last Post: 08-07-2000, 06:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links