How do I get and insert data from vb code

I have upload functionality in my asp.net application and everything is working fine.
I want to store the data and time every time a file gets uploaded to the server. Does any one know how to do this from the VB file (passing the parameter config_key)

There are 2 tables in my SQL:

Upload_Config table:
Config_key (PK)
File_Name
File_Type_Key (FK)
File_Title
File_Description
File_Path
Auto_Email
Active

The second table is where I want to store a date and time every time an upload occurs for a file:

Upload_History table:
Config_Key (FK)
Uploaded_DateTime

The tableview is written in the VB file.

My aspx file looks like this:


<asp:Content ID="cMain" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<div id="body" >
    <div class="container">
        <h3>Upload : Upload Files </h3>
        <div class="spacer">&nbsp;</div>  
        <asp:Table ID="tUpload" runat="server">
        </asp:Table>
        <asp:Label ID="lblError" runat="server" Text="" Visible="false"></asp:Label>
    </div>
</div>
</asp:Content>
Private Sub Upload_Click(ByVal source As Object, ByVal e As System.EventArgs)
 
        Dim Config_Key As String = CType(source, Button).CommandArgument.ToString
        Dim DA As New DataAccess
        Dim DS As New DataSet
 
        Dim q As String
 
        q = "View_Upload_Config_By_Config_Key " + Config_Key
 
        Try
            DA.RunQueryDataSetResult(DS, ConfigurationManager.ConnectionStrings("KHConnectionString").ToString, q, "Upload")
        Catch ex As Exception
            Exit Sub
        End Try
 
        Dim fuUpload As FileUpload = tUpload.FindControl("fuUpload" + Config_Key)
 
        If fuUpload.HasFile = False Then
            lblError.Text = "You must choose a file!"
            lblError.Visible = True
            Exit Sub
        End If
 
        q = Server.MapPath(DS.Tables("Upload").Rows(0).Item("File Path").ToString) + DS.Tables("Upload").Rows(0).Item("File Name").ToString + "." + DS.Tables("Upload").Rows(0).Item("File Extension").ToString
 
        Try
            fuUpload.SaveAs(Server.MapPath(DS.Tables("Upload").Rows(0).Item("File Path").ToString) + DS.Tables("Upload").Rows(0).Item("File Name").ToString + "." + DS.Tables("Upload").Rows(0).Item("File Extension").ToString)
        Catch ex As Exception
            lblError.Text = "Unable to upload file!"
            lblError.Visible = True
            Exit Sub
        End Try
 
        lblError.Visible = False
 
    End Sub

Open in new window

JessyRobinson1234Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JessyRobinson1234Author Commented:
I added this code to it but it doesn't like it


        Dim conString As String = "Data Source=EGLSMSQL23\Logistics;Initial Catalog=KnowledgeHarvest;Persist Security Info=True;User ID=knowledge;Password=tesVraH"

        Dim objConn As SqlConnection = New SqlConnection(conString)
     
        objConn.Open()

          Dim cmd = New SqlCommand("Insert_Upload_History", objConn)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.Add(Config_Key) ----------> Error: The SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects.
        cmd.ExecuteNonQuery()

        objConn.Close()
0
JessyRobinson1234Author Commented:
I solved it:

 Dim conString As String = ConfigurationManager.ConnectionStrings("KHConnectionString").ToString

        Dim objConn As SqlConnection = New SqlConnection(conString)
     
        objConn.Open()

        Dim cmd = New SqlCommand("Insert_Upload_History", objConn)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.Add("@Config_Key", SqlDbType.Int).Value = Config_Key

        cmd.ExecuteNonQuery()

        objConn.Close()
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.