Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 29th, 2008, 01:43 AM
Authorized User
 
Join Date: Jul 2008
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to TashaAT
Default Need help customizing exsisting store

I bought an ecommerce store full source code and now I need to add and change things
The source code is in Visual Basic the add ins I am trying to do is:
A Bulk upload from an excel spreadsheet to the SQL database - having some problems there (see this post http://forums.asp.net/p/1296511/2519083.aspx#2519083)
Then I also want to do the following:
Add a field in my products the will be linked to a regions field this field is also in the User registration. The idea is that the user will only be able to see products that is in his/her area.
The other thing that I need to get done is that each region has its own payment gate that will be automatically linked to the log in.
Any ideas on where I can even start to look?
I have added the fields to the database I am just not sure how on earth I am going to link it all up - do I do SQL queries on the on Click events of buttons?
Thanks for the help :)
I am using Visual Studio 2005 and SQL 2005



 
Old August 3rd, 2008, 02:36 PM
Authorized User
 
Join Date: Jul 2008
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to TashaAT
Default

Okay I will just reply to my own topics....
I am still struggling with this which seems to be turning into a three headed monster
VB seems to have a problem with this part
  End If
            If D2ProductID = 0 Then
                D2ProductID = _
                Convert.ToInt64(D2Adapter.InsertProductsQuery(D2Pr oductName As String, D2ProductShortDescrip As String, D2ProductLongDescrip As String, D2ProductPrice As System.Nullable(Of Decimal), D2ProductStockLevel As System.Nullable(Of Integer), D2ProductActive As Boolean, D2ProductShipCode As System.Nullable(Of Integer), D2ProductSpecial As Boolean, D2ProductSortOrder As Integer, D2ProductCatID As System.Nullable(Of Integer), D2ProductWeight As Integer, D2ProductImage1 As String, D2ProductImage2 As String, D2ProductImage3 As String, D2ProductImage4 As String, D2TaxExempt As Boolean, D2EstimatedShipping As Decimal, D2AllowReviews As Boolean, D2IsDownload As Boolean, D2DownloadPath As String, D2DownloadSize As System.Nullable(Of Integer), D2DownloadCap As Integer, D2DownloadGUID As String, D2SoftwareVersion As String, D2DownloadBinary() As Byte, D2FileType As String, D2FileName As String, D2DownloadExpiry As Integer, D2DateAdded As Date, D2ProductCode As String, D2Manufacturer As String, D2CatID2 As System.Nullable(Of Integer), D2PreviousPrice As System.Nullable(Of Decimal), D2ProductArea As String, D2ProductID As Integer) As Integer
                LabelImport.Text &= "Products Imported " & " ID:" & D2ProductID & ". <br>"


The error is that Argument not specified for parameter but it is usually only for the first 5 so I thought (I am awfully clever here) I will just delete the first five! No luck there it just move to the next five?
Is the string to long??

Even though the error seems to think the argument is not specified I believe it is - maybe I am wrong there?
I have a dataset with a query called InsertProductsQuery and all the fields are the same EXCACTLY I also have :
set default values for loop
            Dim D2ProductID As Integer = Convert.ToString(reader("ProductID"))
            Dim D2ProductName As String = Convert.ToString(reader("ProductName"))
            Dim D2ProductShortDescrip As String = Convert.ToString(reader("ProductShortDescrip"))
            Dim D2ProductLongDescrip As String = Convert.ToString(reader("ProductLongDescrip"))
            Dim D2ProductPrice As System.Nullable(Of Decimal) = Convert.ToString(reader("ProductPrice"))
            Dim D2ProductStockLevel As System.Nullable(Of Integer) = Convert.ToString(reader("ProductStockLevel"))
            Dim D2ProductActive As Boolean = Convert.ToString(reader("ProductActive"))
            Dim D2ProductShipCode As System.Nullable(Of Integer) = Convert.ToString(reader("ProductShipCode"))
            Dim D2ProductSpecial As Boolean = Convert.ToString(reader("ProductSpecial"))
            Dim D2ProductSortOrder As Integer = Convert.ToString(reader("ProductSortOrder"))
            Dim D2ProductCatID As System.Nullable(Of Integer) = Convert.ToString(reader("ProductCatID"))
            Dim D2ProductWeight As Integer = Convert.ToString(reader("ProductWeight"))
            Dim D2ProductImage1 As String = Convert.ToString(reader("ProductImage1")) GOES ON ON AND ON..................................but everything is in there
and then again
Protected Function ImportIntoProducts(ByVal D2ProductArea As String, ByVal D2ProductName As String, _
        ByVal D2ProductShortDescrip As String, ByVal D2ProductLongDescrip As String, ByVal D2ProductPrice As String, ByVal D2ProductStockLevel As String, ByVal D2ProductActive As String, ByVal D2ProductShipCode As String, ByVal D2ProductSpecial As String, ByVal D2ProductSortOrder As String, ByVal D2ProductCatID As String, ByVal D2ProductWeight As String, ByVal D2ProductImage1 As String, ByVal D2ProductImage2 As String, ByVal D2ProductImage3 As String, ByVal D2ProductImage4 As String, ByVal D2TaxExempt As String, ByVal D2EstimatedShipping As String, ByVal D2AllowReviews As String, ByVal D2IsDownload As String, ByVal D2DownloadPath As String, ByVal D2DownloadSize As String, ByVal D2DownloadCap As String, ByVal D2DownloadGUID As String, ByVal D2SoftwareVersion As String, ByVal D2DownloadBinary As String, ByVal D2FileType As String, ByVal D2FileName As String, ByVal D2DownloadExpiry As String, ByVal D2DateAdded As String, ByVal D2ProductCode As String, _
        ByVal D2Manufacturer As String, ByVal D2CatID2 As String, ByVal D2PreviousPrice As String, ByVal D2ProductID As Integer) As Integer
        D2ProductID = Left(D2ProductID, 100)
        D2ProductName = Left(D2ProductName, 100)
        D2ProductShortDescrip = Left(D2ProductShortDescrip, 100)

WHERE AM I GOING WRONG WHAT AM I MISSING??


 
Old August 3rd, 2008, 03:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi there..

Just a quick question.. Convert.toint64 (...) as integer?????? what is that??

Also, you are defining each variable inside the insertproductquery?? so all of them are null, or at least the one nullables, so, what are you trying to do????

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 3rd, 2008, 03:18 PM
Authorized User
 
Join Date: Jul 2008
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to TashaAT
Default

Convert.ToInt32(ADAPTERNAME.INSERTQUERYNAME(FIELD NAMES IN TABLE)

I am trying to take an excel spreadsheet and import it into a SQL database.

I have A dataset with a GetDataQuery and an InsertData Query the insert data query:
INSERT INTO SLProducts
                      (D2ProductName, D2ProductShortDescrip, D2ProductLongDescrip, D2ProductPrice, D2ProductStockLevel, GOES ON AND ON AND ON)
VALUES (@D2ProductName,@D2ProductShortDescrip,@D2ProductL ongDescrip,@D2ProductPrice,@D2ProductStockLevel,@D 2ProductActive,.........)

Do you want me to post the entire aspx.vb file? Will that help?

 
Old August 3rd, 2008, 03:26 PM
Authorized User
 
Join Date: Jul 2008
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to TashaAT
Default

The entire code behind:
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Partial Class UploadProducts
    Inherits System.Web.UI.Page

    Protected Sub ButtonUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonUpload.Click
        PanelUpload.Visible = True
        PanelView.Visible = False
        PanelImport.Visible = False
    End Sub


    Protected Function ExcelConnection() As OleDbCommand

        ' Connect to the Excel Spreadsheet
        Dim xConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                    "Data Source=" & Server.MapPath("~/ExcelImport.xls") & ";" & _
                    "Extended Properties=Excel 8.0;"

        ' create your excel connection object using the connection string
        Dim objXConn As New OleDbConnection(xConnStr)
        objXConn.Open()

        ' use a SQL Select command to retrieve the data from the Excel Spreadsheet
        ' the "table name" is the name of the worksheet within the spreadsheet
        ' in this case, the worksheet name is "Members" and is coded as: [Members$]
        Dim objCommand As New OleDbCommand("SELECT * FROM [Products$]", objXConn)
        Return objCommand
        'the products$ is the worksheet name in excel not the workbook
    End Function
    Protected Sub ButtonView_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
         Handles ButtonView.Click
        PanelUpload.Visible = False
        PanelView.Visible = True
        PanelImport.Visible = False

        ' Create a new Adapter
        Dim objDataAdapter As New OleDbDataAdapter()

        ' retrieve the Select command for the Spreadsheet
        objDataAdapter.SelectCommand = ExcelConnection()

        ' Create a DataSet
        Dim objDataSet As New DataSet()
        ' Populate the DataSet with the spreadsheet worksheet data
        objDataAdapter.Fill(objDataSet)

        ' Bind the data to the GridView
        GridViewExcel.DataSource = objDataSet.Tables(0).DefaultView
        GridViewExcel.DataBind()

    End Sub

    Protected Sub ButtonImport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonImport.Click
        PanelUpload.Visible = False
        PanelView.Visible = False
        PanelView.Visible = True
        labelImport.Text = "" ' resert to blank
        ' retrieve the Select Command for the worksheet data
        Dim objCommand As New OleDbCommand()
        objCommand = ExcelConnection()

        ' create a DataReader
        Dim reader As OleDbDataReader
        reader = objCommand.ExecuteReader()


        Dim counter As Integer = 0 ' used for testing your import in smaller increments

        While reader.Read()
            counter = counter + 1 ' counter to exit early for testing...

            ' set default values for loop
            Dim D2ProductID As Integer = Convert.ToString(reader("ProductID"))
            Dim D2ProductName As String = Convert.ToString(reader("ProductName"))
            Dim D2ProductShortDescrip As String = Convert.ToString(reader("ProductShortDescrip"))
            Dim D2ProductLongDescrip As String = Convert.ToString(reader("ProductLongDescrip"))
            Dim D2ProductPrice As System.Nullable(Of Decimal) = Convert.ToString(reader("ProductPrice"))
            Dim D2ProductStockLevel As System.Nullable(Of Integer) = Convert.ToString(reader("ProductStockLevel"))
            Dim D2ProductActive As Boolean = Convert.ToString(reader("ProductActive"))
            Dim D2ProductShipCode As System.Nullable(Of Integer) = Convert.ToString(reader("ProductShipCode"))
            Dim D2ProductSpecial As Boolean = Convert.ToString(reader("ProductSpecial"))
            Dim D2ProductSortOrder As Integer = Convert.ToString(reader("ProductSortOrder"))
            Dim D2ProductCatID As System.Nullable(Of Integer) = Convert.ToString(reader("ProductCatID"))
            Dim D2ProductWeight As Integer = Convert.ToString(reader("ProductWeight"))
            Dim D2ProductImage1 As String = Convert.ToString(reader("ProductImage1"))
            Dim D2ProductImage2 As String = Convert.ToString(reader("ProductImage2"))
            Dim D2ProductImage3 As String = Convert.ToString(reader("ProductImage3"))
            Dim D2ProductImage4 As String = Convert.ToString(reader("ProductImage4"))
            Dim D2TaxExempt As Boolean = Convert.ToString(reader("TaxExempt"))
            Dim D2EstimatedShipping As Decimal = Convert.ToString(reader("EstimatedShipping"))
            Dim D2AllowReviews As Boolean = Convert.ToString(reader("AllowReviews"))
            Dim D2IsDownload As Boolean = Convert.ToString(reader("IsDownload"))
            Dim D2DownloadPath As String = Convert.ToString(reader("DownloadPath"))
            Dim D2DownloadSize As System.Nullable(Of Integer) = Convert.ToString(reader("DownloadSize"))
            Dim D2DownloadCap As Integer = Convert.ToString(reader("DownloadCap"))
            Dim D2DownloadGUID As String = Convert.ToString(reader("DownloadGUID"))
            Dim D2SoftwareVersion As String = Convert.ToString(reader("SoftwareVersion"))
            Dim D2FileType As String = Convert.ToString(reader("FileType"))
            Dim D2FileName As String = Convert.ToString(reader("FileName"))
            Dim D2DownloadExpiry As Integer = Convert.ToString(reader("DownloadExpiry"))
            Dim D2DateAdded As Date = Convert.ToString(reader("DateAdded"))
            Dim D2ProductCode As String = Convert.ToString(reader("ProductCode"))
            Dim D2Manufacturer As String = Convert.ToString(reader("Manufacturer"))
            Dim D2CatID2 As System.Nullable(Of Integer) = Convert.ToString(reader("CatID2"))
            Dim D2PreviousPrice As System.Nullable(Of Decimal) = Convert.ToString(reader("PreviousPrice"))
            Dim D2ProductArea As String = Convert.ToString(reader("ProductArea"))




        End While
        reader.Close()


    End Sub

    Protected Sub ButtonUploadFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonUploadFile.Click

        If FileUploadExcel.HasFile Then
            Try
                ' alter path for your project
                FileUploadExcel.SaveAs(Server.MapPath("~/ExcelImport.xls"))
                LabelUpload.Text = "Upload File Name: " & _
                     FileUploadExcel.PostedFile.FileName & "<br>" & _
                     "Type: " & _
                     FileUploadExcel.PostedFile.ContentType & _
                     " File Size: " & _
                     FileUploadExcel.PostedFile.ContentLength & " kb<br>"
            Catch ex As Exception
                LabelUpload.Text = "Error: " & ex.Message.ToString
            End Try
        Else
            LabelUpload.Text = "Please select a file to upload."
        End If

    End Sub


    Protected Function ImportIntoProducts(ByVal D2ProductArea As String, ByVal D2ProductName As String, _
        ByVal D2ProductShortDescrip As String, ByVal D2ProductLongDescrip As String, ByVal D2ProductPrice As String, ByVal D2ProductStockLevel As String, ByVal D2ProductActive As String, ByVal D2ProductShipCode As String, ByVal D2ProductSpecial As String, ByVal D2ProductSortOrder As String, ByVal D2ProductCatID As String, ByVal D2ProductWeight As String, ByVal D2ProductImage1 As String, ByVal D2ProductImage2 As String, ByVal D2ProductImage3 As String, ByVal D2ProductImage4 As String, ByVal D2TaxExempt As String, ByVal D2EstimatedShipping As String, ByVal D2AllowReviews As String, ByVal D2IsDownload As String, ByVal D2DownloadPath As String, ByVal D2DownloadSize As String, ByVal D2DownloadCap As String, ByVal D2DownloadGUID As String, ByVal D2SoftwareVersion As String, ByVal D2DownloadBinary As String, ByVal D2FileType As String, ByVal D2FileName As String, ByVal D2DownloadExpiry As String, ByVal D2DateAdded As String, ByVal D2ProductCode As String, _
        ByVal D2Manufacturer As String, ByVal D2CatID2 As String, ByVal D2PreviousPrice As String, ByVal D2ProductID As Integer) As Integer
        D2ProductID = Left(D2ProductID, 100)
        D2ProductName = Left(D2ProductName, 100)
        D2ProductShortDescrip = Left(D2ProductShortDescrip, 100)
        D2ProductLongDescrip = Left(D2ProductLongDescrip, 200)
        D2ProductPrice = Left(D2ProductPrice, 100)
        D2ProductStockLevel = Left(D2ProductStockLevel, 100)
        D2ProductActive = Left(D2ProductActive, 100)
        D2ProductShipCode = Left(D2ProductShipCode, 100)
        D2ProductSpecial = Left(D2ProductSpecial, 100)
        D2ProductSortOrder = Left(D2ProductSortOrder, 100)
        D2ProductCatID = Left(D2ProductCatID, 100)
        D2ProductWeight = Left(D2ProductWeight, 100)
        D2ProductImage1 = Left(D2ProductImage1, 100)
        D2ProductImage2 = Left(D2ProductImage2, 100)
        D2ProductImage3 = Left(D2ProductImage3, 100)
        D2ProductImage4 = Left(D2ProductImage4, 100)
        D2TaxExempt = Left(D2TaxExempt, 100)
        D2EstimatedShipping = Left(D2EstimatedShipping, 100)
        D2AllowReviews = Left(D2AllowReviews, 100)
        D2IsDownload = Left(D2IsDownload, 100)
        D2DownloadPath = Left(D2DownloadPath, 100)
        D2DownloadSize = Left(D2DownloadSize, 100)
        D2DownloadCap = Left(D2DownloadCap, 100)
        D2DownloadGUID = Left(D2DownloadGUID, 100)
        D2SoftwareVersion = Left(D2SoftwareVersion, 100)
        D2DownloadBinary = Left(D2DownloadBinary, 100)
        D2FileType = Left(D2FileType, 100)
        D2FileName = Left(D2FileName, 100)
        D2DownloadExpiry = Left(D2DownloadExpiry, 100)
        D2DateAdded = Left(D2DateAdded, 100)
        D2ProductCode = Left(D2ProductCode, 100)
        D2Manufacturer = Left(D2Manufacturer, 100)
        D2CatID2 = Left(D2CatID2, 100)
        D2PreviousPrice = Left(D2PreviousPrice, 100)
        D2ProductArea = Left(D2ProductArea, 100)

        Dim ProductID As Integer = 0
        Try
            Dim D2Adapter As New ProductImpDataSetTableAdapters.SLProductsTableAdap ter
            Dim SLProductsDataTable As ProductImpDataSet.SLProductsDataTable = Nothing
            SLProductsDataTable = D2Adapter.GetProductsData
            If Not SLProductsDataTable Is Nothing Then
                If SLProductsDataTable.Rows.Count > 0 Then
                    If Not SLProductsDataTable(0).D2ProductID Then
                        D2ProductID = SLProductsDataTable(0).D2ProductID
                        LabelImport.Text &= "Product Found, Not Imported:"&"ID:"& D2ProductID & ".<br>"

                    End If

                End If
            End If
            If D2ProductID = 0 Then
                D2ProductID = _
                Convert.ToInt64(D2Adapter.InsertProductsQuery(D2Pr oductName As String, D2ProductShortDescrip As String, D2ProductLongDescrip As String, D2ProductPrice As System.Nullable(Of Decimal), D2ProductStockLevel As System.Nullable(Of Integer), D2ProductActive As Boolean, D2ProductShipCode As System.Nullable(Of Integer), D2ProductSpecial As Boolean, D2ProductSortOrder As Integer, D2ProductCatID As System.Nullable(Of Integer), D2ProductWeight As Integer, D2ProductImage1 As String, D2ProductImage2 As String, D2ProductImage3 As String, D2ProductImage4 As String, D2TaxExempt As Boolean, D2EstimatedShipping As Decimal, D2AllowReviews As Boolean, D2IsDownload As Boolean, D2DownloadPath As String, D2DownloadSize As System.Nullable(Of Integer), D2DownloadCap As Integer, D2DownloadGUID As String, D2SoftwareVersion As String, D2DownloadBinary() As Byte, D2FileType As String, D2FileName As String, D2DownloadExpiry As Integer, D2DateAdded As Date, D2ProductCode As String, D2Manufacturer As String, D2CatID2 As System.Nullable(Of Integer), D2PreviousPrice As System.Nullable(Of Decimal), D2ProductArea As String, D2ProductID As Integer) As Integer
                LabelImport.Text &= "Products Imported " & " ID:" & D2ProductID & ". <br>"




            End If

            Return D2ProductID

        Catch ex As Exception
            LabelImport.Text &= "" & ex.ToString & "<br/>"
            Return 0


        End Try
    End Function
End Class






The ASPX
<%@ Page Language="VB" MasterPageFile="~/SLMaster.master" AutoEventWireup="false" CodeFile="UploadProducts.aspx.vb" Inherits="UploadProducts" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <table style="width: 517px; height: 117px">
        <tr>
    <td style="width: 111px">
    <asp:Button ID="ButtonUpload" runat="server"
    text="Upload Excel Spreadsheet" />
        <asp:Panel ID= "PanelUpload" runat="server" Visible="false">
        Please select an Excel file to import:<br />
        <asp:FileUpload ID="FileUploadExcel" runat="server" />
        <br /><br />
        <asp:Button ID="ButtonUploadFile" runat="server" Text="Upload File" />
        <br /><br />
        <asp:Label ID="LabelUpload" runat="server" Text=""></asp:Label>
        </asp:Panel>
    </td>
    <td style="width: 118px">
    <asp:Button ID="ButtonView" runat="server"
    text="View Excel Data" />
        <asp:Panel ID="PanelView" runat="server">
            <asp:GridView ID="GridViewExcel" runat="server" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical">
                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="#DCDCDC" />
            </asp:GridView>
        </asp:Panel>
    </td>
    <td style="width: 3px">
    <asp:Button ID="ButtonImport" runat="server"
    text="Import Excel Data" />
        <asp:Panel ID="PanelImport" runat="server">
        </asp:Panel>
        <asp:Label ID="LabelImport" runat="server" Text="Label"></asp:Label></td>
        </tr>
    </table>
</asp:Content>



 
Old August 3rd, 2008, 04:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Ok.. a couple of things I see:

Protected Sub ButtonImport_Click... Does nothing.. you open a reader, then you go through it doing nothing, because the variables dies in each loop.
An again.. if insertproductsquery is already defined (looks like it is), then why are you just not passing the data you want to insert???

Also since you have a parametrized insert, you should be adding parameters to the insert query and then fill those parameters...



HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 4th, 2008, 12:38 AM
Authorized User
 
Join Date: Jul 2008
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to TashaAT
Default

There is three things that happen
1. The client uploads the excelspreadsheet and it a label shows the name,size and type of the excelspreadsheet
2.The data gets imported into a datagrid view so that you can see what you are importing
3.The data now only gets imported into the SQL DB
That is why you wil see three buttons
Upload, View and Import

It is only the import part that does not work - the last step. You keep asking why dont I just pass the data I want to insert - that is what I am trying to do in the last step but for the life of me I can not get it to work if you if think I am making it way to complicated (which I think is the case) can you please help me to make it simple and just get it to work?
Thanks!

 
Old August 4th, 2008, 09:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Again I will point out the same problem I saw.

This line:
Code:
Convert.ToInt64(D2Adapter.InsertProductsQuery(D2ProductName As String, D2ProductShortDescrip As String, D2ProductLongDescrip As String, D2ProductPrice As System.Nullable(Of Decimal), D2ProductStockLevel As System.Nullable(Of Integer), D2ProductActive As Boolean, D2ProductShipCode As System.Nullable(Of Integer), D2ProductSpecial As Boolean, D2ProductSortOrder As Integer, D2ProductCatID As System.Nullable(Of Integer), D2ProductWeight As Integer, D2ProductImage1 As String, D2ProductImage2 As String, D2ProductImage3 As String, D2ProductImage4 As String, D2TaxExempt As Boolean, D2EstimatedShipping As Decimal, D2AllowReviews As Boolean, D2IsDownload As Boolean, D2DownloadPath As String, D2DownloadSize As System.Nullable(Of Integer), D2DownloadCap As Integer, D2DownloadGUID As String, D2SoftwareVersion As String, D2DownloadBinary() As Byte, D2FileType As String, D2FileName As String, D2DownloadExpiry As Integer, D2DateAdded As Date, D2ProductCode As String, D2Manufacturer As String, D2CatID2 As System.Nullable(Of Integer), D2PreviousPrice As System.Nullable(Of Decimal), D2ProductArea As String, D2ProductID As Integer) As Integer
Doesn't work! Read it, you are not passing data, you are passing something that looks like variable definitions. What if you take out all the AS ..., Even the last one. A convert already resolves to the correct type of data.

try that...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 6th, 2008, 04:33 AM
Authorized User
 
Join Date: Jul 2008
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to TashaAT
Default

Hi thanks to the help from here and the wonderfull guy from D2 I came right :)
THE SOLUTION:
Imports System.IO
Imports System.Data.OleDb
Imports System.Data
Partial Class DatabaseImport
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' SitelockFunction.ProtectAdminPage()
        UploadAndImportExcelFile()
    End Sub

    Protected Sub UploadAndImportExcelFile()
        If (FileUpload1.HasFile And Path.GetExtension(FileUpload1.PostedFile.FileName) .ToLower() = ".xls") Then
            ' upload the file to a dir named 'ExcelImport'
            Dim objXConn As OleDbConnection = New OleDbConnection
            Dim ExcelProdDS As DataSet = New DataSet
            Try
                FileUpload1.PostedFile.SaveAs(Server.MapPath(".") & "\ExcelImport\ExcelImportFile.xls")
                ' the file has been uploaded, now read it:
                ' Connect to the Excel Spreadsheet
                Dim xConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                            "Data Source=" & Server.MapPath(".") & "\ExcelImport\ExcelImportFile.xls" & ";" & _
                            "Extended Properties=Excel 8.0;"

                ' create your excel connection object using the connection string
                objXConn.ConnectionString = xConnStr

                Dim objCommand As OleDbCommand = New OleDbCommand
                objCommand.CommandType = Data.CommandType.Text
                objCommand.CommandText = "SELECT * FROM [Products$]"
                objCommand.Connection = objXConn
                objXConn.Open()


                Dim objAdapter As OleDbDataAdapter = New OleDbDataAdapter
                objAdapter.SelectCommand = objCommand
                objAdapter.Fill(ExcelProdDS)
                ' now we have the data in a dataset, loop through and add to DB:
                Dim dr As DataRow

                Dim dbTrans As SitelockDataTransaction = New SitelockDataTransaction
                Dim FileTrans As SitelockFileHandler = New SitelockFileHandler
                Label2.Text = "Imported.... "
                Label2.Visible = True
                Dim i As Integer = 0
                Dim NewProdID As Integer = 0
                For Each dr In ExcelProdDS.Tables(0).Rows
                    NewProdID = dbTrans.AddNewProduct(CheckNullStr(Left(dr("D2Prod uctName"), 50)), _
                                                      CheckNullStr(Left(dr("D2ProductShortDescrip"), 250)), _
                                                      CheckNullStr(dr("D2ProductLongDescrip")), _
                                            CheckNullDecimal(dr("D2ProductPrice")), _
                                            CheckNullInt(dr("D2ProductCatID")), _
                                            CheckNullBool(dr("D2ProductActive")), _
                                            CheckNullDecimal(dr("D2ProductWeight")), _
                                            CheckNullInt(dr("D2ProductStockLevel")), _
                                            CheckNullDecimal(dr("D2EstimatedShipping")), _
                                            CheckNullBool(dr("D2TaxExempt")), _
                                            CheckNullBool(dr("D2ProductSpecial")), _
                                            0, _
                                            CheckNullStr(dr("D2ProductCode")), _
                                            CheckNullStr(dr("D2Manufacturer")), _
                                            CheckNullInt(dr("D2CatID2")), _
                                            CheckNullDecimal(dr("D2PreviousPrice")))

                    ' we've now got the new product ID so add the additional fields:
                    FileTrans.UploadImageToDB(1, NewProdID, CheckNullStr(dr("D2ProductImage1")))
                    FileTrans.UploadImageToDB(2, NewProdID, CheckNullStr(dr("D2ProductImage2")))
                    FileTrans.UploadImageToDB(3, NewProdID, CheckNullStr(dr("D2ProductImage3")))
                    FileTrans.UploadImageToDB(4, NewProdID, CheckNullStr(dr("D2ProductImage4")))

                    Label2.Text += dr("D2ProductName") & ","
                    i += 1
                Next
                Label1.Text = i & " products imported."
                Label1.ForeColor = Drawing.Color.Green
                Label1.Visible = True
                Label2.Visible = True
            Catch ex As Exception
                Label1.Text = "An error occurred: " & ex.Message
                Label1.Visible = True
            Finally
                If objXConn.State = ConnectionState.Open Then
                    objXConn.Close()
                End If
                ExcelProdDS.Dispose()
            End Try
        Else
            Label1.Text = "Please select an Excel file to import"
            Label1.Visible = True
        End If
    End Sub


    Protected Function CheckNullStr(ByVal inputStr As Object) As String
        If IsDBNull(inputStr) Then
            Return ""
        Else
            Return inputStr
        End If
    End Function

    Protected Function CheckNullInt(ByVal inputStr As Object) As Integer
        If IsDBNull(inputStr) Or Not IsNumeric(inputStr) Then
            Return 0
        Else
            Return inputStr
        End If
    End Function

    Protected Function CheckNullBool(ByVal inputStr As Object) As Boolean
        If IsDBNull(inputStr) Then
            Return False
        Else
            Return inputStr
        End If
    End Function

    Protected Function CheckNullDecimal(ByVal inputStr As Object) As Decimal
        If IsDBNull(inputStr) Then
            Return 0.0
        Else
            Return inputStr
        End If
    End Function


End Class







Similar Threads
Thread Thread Starter Forum Replies Last Post
APPEND TO ALREADY EXSISTING HTML OR ASP FILE? ALEX_GRIM Classic ASP Basics 11 February 2nd, 2005 05:40 PM
APPEND TO ALREADY EXSISTING HTML OR ASP FILE? ALEX_GRIM Classic ASP Professional 0 January 11th, 2005 11:55 PM
Customizing Output bmains SQL Server 2000 1 January 13th, 2004 05:23 PM
Customizing danielwajnberg Crystal Reports 1 December 17th, 2003 08:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.