[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I get and insert data from vb code

Posted on 2008-11-12
2
Medium Priority
?
228 Views
Last Modified: 2013-11-08
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

0
Comment
Question by:JessyRobinson1234
  • 2
2 Comments
 

Author Comment

by:JessyRobinson1234
ID: 22943729
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
 

Accepted Solution

by:
JessyRobinson1234 earned 0 total points
ID: 22943862
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question