vks.gautam1
Well-known member
Here im import data from Text file to Msaccess Database.
Data structure in Notepad is
im storing this data in string & then split that & store to a array variable.
if i give cmd parameter
" .Add("@Date", OleDbType.date).Value = data(0)"
then this give error " Cannot convert string to date." so i do this
".Add("@Date", OleDbType.varchar).Value = data(0)"
Is there any better way to do this. Or this is ok
Data structure in Notepad is
VB.NET:
22-Jan-09|919876165328|9878216613|
im storing this data in string & then split that & store to a array variable.
if i give cmd parameter
" .Add("@Date", OleDbType.date).Value = data(0)"
then this give error " Cannot convert string to date." so i do this
".Add("@Date", OleDbType.varchar).Value = data(0)"
Is there any better way to do this. Or this is ok
VB.NET:
Dim file_name As String = "E:\hello.txt"
Dim txtline, q, data(2) As String
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
If System.IO.File.Exists(file_name) = True Then
Dim objreader As New System.IO.StreamReader(file_name)
Do While objreader.Peek <> -1
' Storing line to string variable
txtline = objreader.ReadLine() & vbNewLine
'breaking the line & stroing to array variable
data = txtline.Split("|")
q = "insert into TAB1 values(@Date,@SNo,@MobNo)"
cn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=E:\dat.mdb;")
cn.Open()
cmd = New OleDbCommand(q, cn)
cmd.Connection = cn
With cmd.Parameters
.Add("@Date", OleDbType.VarChar).Value = data(0)
.Add("@SNo", OleDbType.VarChar).Value = data(1)
.Add("@MobNo", OleDbType.VarChar).Value = data(2)
End With
cmd.ExecuteNonQuery()
Loop
End If
MessageBox.Show("Data Saved")