navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

Best approach to update server db from local machine

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> Best approach to update server db from local machine
Page: [1]
 
DaveKstl

 

Posts: 547
Joined: 4/21/2004
Status: offline

 
Best approach to update server db from local machine - 2/4/2008 9:28:03   
Periodically I receive a spreadsheet with the latest customer information. I need to use this data to update an access db on a server. What is a good approach to this update process?

The process I develop has to be something that an average computer skills person might be able to do. Presently I pull the file down, manipulate the access data on my machine and then push it up. Going forward I am looking to turn the db maintenance to someone else, writing an update query for existing records and a append or insert for the records that are new.

I would appreciate comments and thoughts.

I can link to the spreadsheet with an access file on a local machine, but I am hoping someone has already created something similar and can share their experience.

Dave

< Message edited by DaveKstl -- 2/4/2008 9:42:02 >
Spooky

 

Posts: 26597
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Best approach to update server db from local machine - 2/4/2008 13:48:04   
Id be wanting to perhaps have an upload routine for the csv to the server then allow the user to insert the csv into the current database?

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to DaveKstl)
rdouglass

 

Posts: 9167
From: Biddeford, ME USA
Status: offline

 
RE: Best approach to update server db from local machine - 2/4/2008 13:51:48   
Is the spreadsheet just 1 worksheet? DO you have ASP.NET?

I have a .NET script I use that is straightforward in terms of dealing with a text file update source. It currently gets a tab-delimited text file (that can easily be a CSV file) and reads it into the TextStream object (.NET version of FSO's). Then runs a SQL connection and checks a current table. It then either UPDATE's or INSERT's based on whether their is a match or not.

I use 2 fields to determine a match and yours will probably be different. This is the full page and the exact code I use (with filenames and paths changed) and it's a page I execute as part of a daily updating sequence. Here it is if it helps any:

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">
  sub Page_Load(sender as Object, e as EventArgs)
        Dim FILENAME As String = Server.MapPath("/mydownloads/download.txt")

        Dim filetoread As String
        filetoread = (FILENAME)
        Dim filestream As StreamReader
        filestream = File.OpenText(filetoread)
        Dim readcontents As String
        readcontents = filestream.ReadToEnd()
        Dim textdelimiter As String
        textdelimiter = Chr(10)
        Dim splitout = Split(readcontents, textdelimiter)

        filestream.Close()

        Dim sConnStr As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("SF").ConnectionString
        Dim cnBKTest As New SqlConnection(sConnStr)

        cnBKTest.Open()

        Dim strSQL As String = ""
        
        Dim i As Integer
        Dim j As Integer
        Dim myTempVal As Integer = 0
        Dim myTempString As String = ""
        
        For i = 1 To UBound(splitout) - 1

            myTempVal = 0

            Dim splitout2 = Split(splitout(i), vbTab)
            For j = 0 To UBound(splitout2)
                If splitout2(j).ToString & "" = "" Then
                    splitout2(j) = "0"
                End If
            Next
                            
            strSQL = "SELECT * FROM tlkp_NSD_Report  WHERE (ReportDate ='" & splitout2(0) & "') AND (AdvertiserID = " & splitout2(1) & ")"
 
            Dim cmdTest As New SqlCommand(strSQL, cnBKTest)
 
            cmdTest.CommandType = Data.CommandType.Text
            
            cmdTest.ExecuteScalar()
            
            Dim reader As SqlDataReader = cmdTest.ExecuteReader()

            If reader.Read() Then
                myTempVal = 1
            End If
            reader.Close()

            If myTempVal = 1 Then
                strSQL = "UPDATE tlkp_NSD_Report SET ReportDate = '" & splitout2(0) & "', AdvertiserID = " & splitout2(1) & ", AdvertiserName  = '" & splitout2(2) & "', AdvertiserCode  = '" & splitout2(3) & "', CampaignID = '" & splitout2(4) & "', CampaignName = '" & splitout2(5) & "', CampaignSpend = " & splitout2(6) & ", CampaignAdjustment = " & splitout2(7) & ", CampaignFees = " & splitout2(8) & ", Visits = " & splitout2(9) & ", Impressions  = " & splitout2(10) & ", Calls = " & splitout2(11) & ", Emails = " & splitout2(12) & ", Coupons = " & splitout2(13) & ", WebLinks = " & splitout2(14) & ", WebEvents  = " & splitout2(15) & ", LastUpdated = '" & splitout2(16) & "'  WHERE (ReportDate ='" & splitout2(0) & "') AND (AdvertiserID = " & splitout2(1) & ")"
            Else
                strSQL = "INSERT INTO tlkp_NSD_Report (ReportDate, AdvertiserID, AdvertiserName, AdvertiserCode, CampaignID, CampaignName, CampaignSpend, CampaignAdjustment, CampaignFees, Visits, Impressions, Calls, Emails, Coupons, WebLinks, WebEvents , LastUpdated) VALUES ('" & splitout2(0) & "'," & splitout2(1) & ",'" & splitout2(2) & "','" & splitout2(3) & "','" & splitout2(4) & "','" & splitout2(5) & "'," & splitout2(6) & "," & splitout2(7) & "," & splitout2(8) & "," & splitout2(9) & "," & splitout2(10) & "," & splitout2(11) & "," & splitout2(12) & "," & splitout2(13) & "," & splitout2(14) & "," & splitout2(15) & ",'" & splitout2(16) & "')"
            End If
            Dim cmdTest2 As New SqlCommand(strSQL, cnBKTest)

            myTempString = myTempString & i & strSQL & "<br />"
            cmdTest2.CommandType = Data.CommandType.Text
            cmdTest2.ExecuteScalar()
            
        Next
        lblOutput.Text = myTempString
        cnBKTest.Close()

    End Sub
</script>

<html>
<head>
<title>Updating NSD Records...</title>
</head>
<body>

<form id="Form1" runat="server">

<asp:label runat="server" id="lblOutput" />

</form>

</body>
</html>


So if something like this works, you'd essentially save the Excel file as a text doc(TSV or CSV) and upload it to the server and then kick off this page / script. Just remeber all bets are off if the Excel file has multiple worksheets.

Hope it helps.

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to DaveKstl)
rdouglass

 

Posts: 9167
From: Biddeford, ME USA
Status: offline

 
RE: Best approach to update server db from local machine - 2/4/2008 13:53:49   
Sorry Spooky, the post been sittin' there for a while and of course you posted while I was typing....:) :)

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to rdouglass)
Spooky

 

Posts: 26597
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Best approach to update server db from local machine - 2/4/2008 16:12:58   
Yours was a longer answer, Ill forgive you ;-)

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to rdouglass)
DaveKstl

 

Posts: 547
Joined: 4/21/2004
Status: offline

 
RE: Best approach to update server db from local machine - 2/11/2008 11:30:25   
I am not sure if we have a .net server. Is there a way to do this using asp?

Using Spooky's scenario, do I push the file to a folder on a server, open a connection then do an update?

Thanks

Dave


(in reply to Spooky)
rdouglass

 

Posts: 9167
From: Biddeford, ME USA
Status: offline

 
RE: Best approach to update server db from local machine - 2/11/2008 14:38:33   
You can use an Excel spreadsheet just like an Access DB by doing something like this for your ASP connection object:

myDSN = "DRIVER=Microsoft Excel Driver (*.xls); DBQ=" & Server.MapPath("/myExcelFiles/MySpreadsheet.xls")

Then (at least as far as I can see) it would involve:

1. Read the records into an array.
2. While loop thru the array, generate and execute a database UPDATE statement for each Excel record.

The trick is making sure you have an ID in each source to match against.

Some hints:

1. Don't use calculated fields. Do a SaveAs with just values if you have to.
2. Keep the spreadsheet simple. More worksheets just cause confusion to me and you want to start simple.
3. Make sure your column data is consistent. If you have dates or numbers, make sure *all* your column cells have valid data for the type in there. I've found this type of connection to an Excell SS is not very forgiving sometimes and very often difficult to troubleshoot so try to get rid of any data validation errors right up front.
4. Try not to use special characters as well. Same reasons as #3.

Hope that helps.

EDIT: Oh yeah, do that first:

quote:

do I push the file to a folder on a server


< Message edited by rdouglass -- 2/11/2008 15:53:08 >


_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to DaveKstl)
DaveKstl

 

Posts: 547
Joined: 4/21/2004
Status: offline

 
RE: Best approach to update server db from local machine - 2/11/2008 17:26:13   
Thanks for the feedback

Dave

(in reply to rdouglass)
Page:   [1]

All Forums >> Web Development >> ASP and Database >> Best approach to update server db from local machine
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts