Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Zero Fields in Database
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Zero Fields in Database

 Post Reply Post Reply
Author
hack_it View Drop Down
Newbie
Newbie
Avatar

Joined: 16 November 2003
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote hack_it Quote  Post ReplyReply Direct Link To This Post Topic: Zero Fields in Database
    Posted: 10 December 2003 at 9:51am
Im trying to read a .csv file in my database fields using the split() function. It seems to be splitting the line into the array perfectly but its when i come to the Sql that its letting me down.

It is accessing the DB but its entering zeroes for the fields. I know its going through the Do while loop correctly as it makes the correct number of records in the DB but with zero values in all.

Heres a snippet of my code, i've included the Sgl query, and the do while loop


aString = "Insert INTO Grades ([StudentID], [ModuleID], [AssignmentNumber], [Mark]) VALUES ('"& U_ID &"', '"& M_ID &"', '"& A_NUM &"', '"& Mrk &"')"

Do While objStreamReader.Peek() <> -1
Dim contents As String = objStreamReader.ReadLine()
Dim textdelimiter as String = ","
Dim splitout = Split(contents,textdelimiter)
U_ID = splitout(0)
M_ID = splitout(1)
A_Num = splitout(2)
Mrk = splitout(3)
myCommand = New OleDbCommand(aString, myConnection)
myCommand.ExecuteNonQuery()
Loop



Has anyone encountered this problem before?? I'm really stuck on it and need help fast.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 10 December 2003 at 10:04am
That seems a pretty dodgy way of reading CSV's. I would use ADO.net to load it into a dataset http://authors.aspalliance.com/ericm/articles/textdb.asp
Back to Top
hack_it View Drop Down
Newbie
Newbie
Avatar

Joined: 16 November 2003
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote hack_it Quote  Post ReplyReply Direct Link To This Post Posted: 10 December 2003 at 10:11am

Ok Mart,

I've had a read of that page, am i right in thinking that i can do someting more to move the data into a relevant table in my database from the dataset??? If so is it the best way to read from a .csv and how is it best achieved?

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 10 December 2003 at 1:59pm
I don't quite know what you mean... If you want to load a database into a data set look at this code


Dim objIdbConn As IDbConnection = New SqlConnection("server=(local);uid=xxx;pwd=xxx;database=xxx")
        Dim objCommand As IDbCommand = New SqlCommand
        Dim objDataAdapter As IDbDataAdapter = New SqlDataAdapter
        Dim objDataSet As New DataSet
        objCommand.CommandText = "exec Query;"
        objCommand.Connection = objIdbConn
        objDataAdapter.SelectCommand = objCommand
        objDataAdapter.Fill(objDataSet)

        DataGrid1.DataSource = objDataSet
        DataGrid1.DataBind()

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 10 December 2003 at 2:01pm
You can do similar with microsoft access by using the System.Data.OleDb namespace instead...
Back to Top
hack_it View Drop Down
Newbie
Newbie
Avatar

Joined: 16 November 2003
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote hack_it Quote  Post ReplyReply Direct Link To This Post Posted: 10 December 2003 at 3:22pm

Mart

I have this process working now.

Im having a problem with one of my other pages.  When a user clicks on the submit button it is suppose to change a field relating to that user in the DB and email them the resultant change.  However, when i click the button, the email seems to be sent before the change is made and as a result they are sent the old data instead of the new.  Have you any idea what cuases such an error?

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 10 December 2003 at 3:31pm

Why so complicated. Let SQL do the job


Dim SQLCon As New SqlClient.SqlConnection("server=(local);uid=zzz;pwd=rrr;data base=test")
Dim myQuery As New SqlClient.SqlCommand
myQuery.CommandText = "BULK INSERT tblImport FROM 'c:\trnexp.csv' WITH (FIELDTERMINATOR = ',',ROWTERMINATOR = '\n')"
myQuery.Connection = SQLCon
SQLCon.Open()
myQuery.ExecuteNonQuery()
SQLCon.Close()

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.