I am having a problem moving the data from a datatable to the SQL2005
table (using VB2005). See code below. The SQL2005 table is empty, the
datatable is being filled from a text file, not from the SQL2005 table.
I have tried various ways, but the SQL table is not updating. Help
would be appreciated.
Code is below
Thanks
Imports System
Imports System.Data
Imports System.Data.Sql Client
Imports System.Data.Ole Db
Imports System.Net
Imports System.IO
Imports SYGNeT3.clsFTP
Imports System.Text
Imports System.Net.Sock ets
Public Class Utility
'************** **********
' other stuff here
'************** ***********
Public Shared Function ReadOGText() As Boolean
Dim MyTime As System.DateTime = "00:00:00"
Console.WriteLi ne("Start " & Now())
Dim ctr As Int32 = 0
Dim strMsg As String = ""
Dim RetVal As Integer = 0
Dim ConStr As String = GetConnectionSt ring()
Dim myConnection As New SqlConnection(C onStr)
If Not (myConnection.S tate = ConnectionState .Open) Then
myConnection.Op en()
Dim sSQL As String = "DELETE FROM tblItems" ' Clean out table
before load from text file
Dim myCommand As New SqlCommand(sSQL , myConnection)
RetVal = myCommand.Execu teNonQuery()
Dim ds As New DataSet()
Dim dt As New DataTable("temp ")
Dim da As New SqlClient.SqlDa taAdapter("SELE CT * FROM
tblItems", ConStr)
ds.Clear()
da.FillSchema(d s, SchemaType.Mapp ed, "temp")
Dim path As String = AppPath(True) & "Incoming\OG.tx t"
Dim sR As IO.StreamReader =
System.IO.File. OpenText(path.T oString)
Dim fileline As String = ""
Try
Do While sR.Peek <> -1
fileline = sR.ReadLine
Dim dr As DataRow = ds.Tables("temp ").NewRow
dr("CompanyNumb er") =
Convert.ToInt32 (fileline.Subst ring(0, 4)) ' 0-4
dr("PriceGroup" ) =
Convert.ToInt16 (fileline.Subst ring(5, 7)) '5-11
dr("ItemCategor yCode") =
Convert.ToInt32 (fileline.Subst ring(12, 5)) '12-16
dr("ItemNumber" ) =
Convert.ToInt32 (fileline.Subst ring(17, 9)) '17-25
dr("ItemDescrip tion") = fileline.Substr ing(26,
30).TrimEnd '26-55
'************** *************** *************** ***********
' the other 400 chars work as well, removed for example
'************** *************** *************** ************
dr("New") = True
dr("Date") = Now()
ds.Tables("temp ").Rows.Add (dr)
ctr += 1
Loop
Console.WriteLi ne("Rows = " & CStr(ctr))
'************** *************** *************** *************** ***********
' This where I am having a problem, getting the data from the temp
table to the
' table in the SQL2005 mdf. I am using VB2005
'************** *************** *************** *************** ***********
Try
sSQL = "INSERT INTO TBLITEMS "
sSQL &= "SELECT temp.* "
sSQL &= "FROM temp;"
Dim myCommand2 As New SqlCommand(sSQL , myConnection)
RetVal = myCommand2.Exec uteNonQuery()
'ds.HasChanges( ) 'false
'da.Fill(ds, "temp")
'da.Update(ds, "tblItems")
Catch e As Exception
'TODO: PutInfo() add error message here
Console.WriteLi ne(e.Message)
End Try
Catch ex As Exception
Console.WriteLi ne(ex.Message)
Finally
If Not (myConnection.S tate = ConnectionState .Closed) Then
myConnection.Cl ose()
sR.Close()
sR = Nothing
GC.Collect()
ReadOGText = True
End Try
Console.WriteLi ne("End " & Now())
End Function
End Class 1 2733
"r1100r98" <pa*****@gmail. com> wrote in message
news:11******** *************@y 43g2000cwc.goog legroups.com... I am having a problem moving the data from a datatable to the SQL2005 table (using VB2005). See code below. The SQL2005 table is empty, the datatable is being filled from a text file, not from the SQL2005 table. I have tried various ways, but the SQL table is not updating. Help would be appreciated. Code is below Thanks
Imports System Imports System.Data Imports System.Data.Sql Client Imports System.Data.Ole Db Imports System.Net Imports System.IO Imports SYGNeT3.clsFTP Imports System.Text Imports System.Net.Sock ets
Public Class Utility '************** ********** ' other stuff here '************** ***********
Public Shared Function ReadOGText() As Boolean Dim MyTime As System.DateTime = "00:00:00" Console.WriteLi ne("Start " & Now()) Dim ctr As Int32 = 0 Dim strMsg As String = "" Dim RetVal As Integer = 0 Dim ConStr As String = GetConnectionSt ring() Dim myConnection As New SqlConnection(C onStr) If Not (myConnection.S tate = ConnectionState .Open) Then myConnection.Op en() Dim sSQL As String = "DELETE FROM tblItems" ' Clean out table before load from text file Dim myCommand As New SqlCommand(sSQL , myConnection) RetVal = myCommand.Execu teNonQuery() Dim ds As New DataSet() Dim dt As New DataTable("temp ") Dim da As New SqlClient.SqlDa taAdapter("SELE CT * FROM tblItems", ConStr) ds.Clear() da.FillSchema(d s, SchemaType.Mapp ed, "temp") Dim path As String = AppPath(True) & "Incoming\OG.tx t" Dim sR As IO.StreamReader = System.IO.File. OpenText(path.T oString) Dim fileline As String = "" Try Do While sR.Peek <> -1 fileline = sR.ReadLine Dim dr As DataRow = ds.Tables("temp ").NewRow dr("CompanyNumb er") = Convert.ToInt32 (fileline.Subst ring(0, 4)) ' 0-4 dr("PriceGroup" ) = Convert.ToInt16 (fileline.Subst ring(5, 7)) '5-11 dr("ItemCategor yCode") = Convert.ToInt32 (fileline.Subst ring(12, 5)) '12-16 dr("ItemNumber" ) = Convert.ToInt32 (fileline.Subst ring(17, 9)) '17-25 dr("ItemDescrip tion") = fileline.Substr ing(26, 30).TrimEnd '26-55
'************** *************** *************** *********** ' the other 400 chars work as well, removed for example
'************** *************** *************** ************ dr("New") = True dr("Date") = Now() ds.Tables("temp ").Rows.Add (dr) ctr += 1 Loop Console.WriteLi ne("Rows = " & CStr(ctr)) '************** *************** *************** *************** ***********
' This where I am having a problem, getting the data from the temp table to the ' table in the SQL2005 mdf. I am using VB2005 '************** *************** *************** *************** ***********
Look as the SqlBulkCopy object.
David This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chris |
last post by:
Hi
I can use a text file as a datasource but am unable to get the datatable to
see the text file as having multiple columns. Everything gets
put into the first column in the datatable. Sample of code and text file
included.
Please help
Regards
|
by: John Wildes |
last post by:
Hello all
I'm going to try and be brief with my question, please tell me if I have the
wrong group.
We are querying transaction data from a DB3 database application. The dates
are stored as text fields. Each date for example 10/31/03 or October 31st
2003 is stored as 10/31/A3 in the system. My reasoning for this is because
they...
|
by: scorpion53061 |
last post by:
Well I had a way to write an array to an excel spreadsheet but on a huge
time critical run it failed iwth the dreaded HRESULT: 0x800A03EC error. It
worked fine when i sampled the data to go in but when it all tried to go in
it bombed.
So I need to write this to a tab delimited file and I sure hope somebody is
awake tonight.
How do I...
|
by: Amit Maheshwari |
last post by:
I need to read text file having data either comma seperated or tab seperated
or any custom seperator and convert into a DataSet in C# .
I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0 to read text file
but could not get the data in correct format.
All columns are not coming in dataset and rows are messing up.
Suggestions...
|
by: SAL |
last post by:
Hello,
Is it possible to read a CSV from the Client, and bind my Datagrid to the
data in the CSV file without uploading the file to the Server first?
I have tried and in Debug mode on my workstation it works fine, but when I
publish the page on our DEV server it doesn't fine the CSV file from the
client.
Has anyone done this before? ...
| |
by: JJ |
last post by:
I have a need to input a large tab delimited text file, which I will parse
to check it has the expected columns, before allowing the user to submit it
to the database. The user may paste the file into a textbox, or upload it
(haven't decided yet).
The problem I have is that the text file consists of around 3000 lines, and
I want to display...
|
by: Roger |
last post by:
I've got two tables in sql2005 which have an 'ntext' field
when I linked the first table in access97 last week using an odbc data
source the access-field type was 'memo'
when I link the 2nd table today, it is linked as a text(255) field,
ditto for the first table if I link it today
if I link the 2nd table using access2003 (and the same...
|
by: =?Utf-8?B?anAybXNmdA==?= |
last post by:
I've got a routine that builds a table using different queries, different SQL
Tables, and adding custom fields.
It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the
table population.
Whenever I call the thread, I pass it a structure containing the table and a
few other parameters. The table goes in as a reference,...
|
by: JamesOo |
last post by:
I have the code below, but I need to make it searchable in query table,
below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only, cannot serch by combine 3 table)
Example I have the query table below, how do I make the code to seach based on the query from this:
SELECT...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |