Print Page | Close Window

Zero Fields in Database

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=7990
Printed Date: 28 March 2026 at 9:02am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Zero Fields in Database
Posted By: hack_it
Subject: Zero Fields in Database
Date 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.



Replies:
Posted By: Mart
Date 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 - http://authors.aspalliance.com/ericm/articles/textdb.asp


Posted By: hack_it
Date 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?



Posted By: Mart
Date 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()



Posted By: Mart
Date Posted: 10 December 2003 at 2:01pm
You can do similar with microsoft access by using the System.Data.OleDb namespace instead...


Posted By: hack_it
Date 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?



Posted By: michael
Date 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()



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net