Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 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 23rd, 2008, 04:34 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 Newby need to import Excel to SQL2005

Hi
I bought D2Store and now I want to add some features to the exsisting package. One of the main features that I need to add is to upload bulk products to the database.
I need help in how to design a form (step by step for dummies help) that will be able to do that.
Thank you for the help!

 
Old July 23rd, 2008, 04:43 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default


C# 2005 for Dummies
 Â

Sounds like you are going to be doing a lot of work here. It would be best if you got started yourself and then ask for pointers with the code.

Forms programming can start simple, but quickly get complicated, so its best to start with a firm idea/spec, and then work from there..

Edit:
You can of course opt for 2008, but some of the newer 2008 features may be confusing if new to C# (IMO).

Rob
http://cantgrokwontgrok.blogspot.com
 
Old July 23rd, 2008, 04:51 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

Okay here is the code for the form that I did:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ProductUpload.aspx.cs" Inherits="ProductUpload" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td>
    <asp:Button ID="ButtonUpload" runat="server"
    Text="Upload Excel Spreadsheet" />
    </td>
    <td>
    <asp:Button ID="ButtonView" runat="server"
    text="View Excel Data" />
    </td>
    <td>
    <asp:Button ID="ButtonImport" runat="server"
    text="Import Excel Data" />
    </td>
    </tr>
    </table>
    <asp:Panel ID="PanelUpload" runat="server" Visible="false" Width="240px">
        <asp:FileUpload ID="FileUploadExcel" runat="server" /><br />
        Please select an excel file to import<br />
        <asp:Button ID="ButtonUploadFile" runat="server" Text="Upload File" OnClick="ButtonUploadFile_Click" />
        <br /><br />
        <asp:Label ID="LabelUpload" runat="server" Text=""></asp:Label>
    </asp:Panel>
    <asp:Panel ID="PanelImport" runat="server" Visible="false">
    </asp:Panel>
    <asp:Panel ID="PanelView" runat="server" Visible="false">
    </asp:Panel>
        &nbsp;
    </div>
    </form>
</body>
</html>


NOW HERE IS WHERE I AM NOT SURE:
The Code BEHIND
CAN I do this (more vb than C#)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ProductUpload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void ButtonUploadFile_Click(object sender, EventArgs e)
{
        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>";
}
}
}

 
Old July 23rd, 2008, 04:57 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

It does not seem to like the
("~ExcelImport.xls)); part it has red lines under it....

 
Old July 23rd, 2008, 04:59 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

OK, so you have two problems here. First off, you need to upload the Excel file.
Secondly, you need to pipe the data in the XLS file into the database correct?

I have to be honest, I've not done much file uploading in ASP.NET, but at a rough
glance the code looks ok. Does it work? Can you upload files using the form?

If so, move to problem 2, if not, what goes wrong?

Rob
http://cantgrokwontgrok.blogspot.com
 
Old July 23rd, 2008, 05:00 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by TashaAT
 It does not seem to like the
("~ExcelImport.xls)); part it has red lines under it....
And what does the compiler say? You need to ensure you give us as much information as possible! ;)

Rob
http://cantgrokwontgrok.blogspot.com
 
Old July 23rd, 2008, 05:50 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

Okay I compiled it :(
This is the MAIN error it gives in my browser
Compiler Error Message: CS0103: The name '_' does not exist in the current context

Source Error:



Line 19: {
Line 20:fileUploadExcel.SaveAs(Server.MapPath("~ExcelIm port.xls"));
Line 21:LabelUpload.Text = "Upload File Name:" & _; FileUploadExcel.PostedFile.FileName & "<br>" & _;
Line 22:"Type: " & _;
Line 23:FileUploadExcel.PostedFile.ContentType & _;

And then there are these:
Error 1 The name '_' does not exist in the current
Error 2 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Error 3 Operator '&' cannot be applied to operands of type 'string' and 'string'
Error 4 The name '_' does not exist in the current
Error 5 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Error 6 The name '_' does not exist in the current
Error 7 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Error 8 The name '_' does not exist in the current context
Error 9 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Error 10 The name '_' does not exist in the current context
Error 11 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Error 12 Operator '&' cannot be applied to operands of type 'int' and 'string'


Okay now where to start?

 
Old July 23rd, 2008, 05:55 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ah, your from a VB background aren't you?

Scratch the underscores, we dont use them in the C# camp. Whitespace is ignored.

Also, strings are concatenated using "+" rather than "&".
You then mark the end of the statement using a ";".

e.g:
Code:
LabelUpload.Text = "Upload File Name: " + 
FileUploadExcel.PostedFile.FileName + "<br>";
Hope that makes sense :)

Rob
http://cantgrokwontgrok.blogspot.com
 
Old July 23rd, 2008, 05:56 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

The Only assignment, call, increment, decrement, and new object expressions can be used as a statement error refers to:
FileUploadExcel
"Type: "
and the
"File Size:"

 
Old July 23rd, 2008, 06:05 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The following:

Code:
LabelUpload.Text = "Upload File Name:" & _;
FileUploadExcel.PostedFile.FileName & "<br>" & _;               
"Type: " & _;
FileUploadExcel.PostedFile.ContentType & _;
"File Size:" & _;
FileUploadExcel.PostedFile.ContentLength & " kb <br>";
Should read:

Code:
LabelUpload.Text = "Upload File Name:"
      + FileUploadExcel.PostedFile.FileName
      + "<br>"
      + "Type: "
      + FileUploadExcel.PostedFile.ContentType 
      + "File Size:" 
      + FileUploadExcel.PostedFile.ContentLength 
      + " kb <br>";
As Rob tried to tell you, you do not use '_' or '&' in C#, and the semi-colon only appears a the end of a 'statement', not at the end of every line (i.e. in the above example there is only one at the end of the last line, not one at the end of the other line).

I find it helps readability to put the '+' at the start of the following line, and indent it.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
import excel to access Vision G Access 1 October 15th, 2008 02:12 PM
Import From excel with n sheets dbellavi SQL Server DTS 1 September 11th, 2007 07:51 AM
newby Tyler Access 1 December 14th, 2005 07:29 AM
Excel IMport Text Help!! money Excel VBA 2 April 30th, 2004 12:43 AM
Excel Data Import bmains ASP.NET 1.x and 2.0 Application Design 4 April 14th, 2004 02:12 PM





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