001.
Imports
System.Data.OleDb
002.
003.
Module
MyModule
004.
005.
006.
007.
008.
Sub
Main()
009.
010.
011.
Dim
myCon
As
New
OleDbConnection()
012.
013.
Dim
myCommand
As
New
OleDbCommand()
014.
015.
Dim
myReader
As
OleDbDataReader
016.
017.
Dim
Query
As
String
=
Nothing
018.
019.
Dim
DBPath
As
String
= _
020.
System.IO.Path.GetDirectoryName( System.Windows.Forms.Application.ExecutablePath ) _
021.
+
"\" + "
販売管理C.mdb"
022.
023.
024.
myCon.ConnectionString = _
025.
"Provider=Microsoft.Jet.OLEDB.4.0;"
& _
026.
"Data Source="
& DBPath &
";"
027.
028.
029.
030.
031.
Try
032.
033.
myCon.Open()
034.
035.
myCommand.Connection = myCon
036.
037.
myCommand.CommandType = System.Data.CommandType.Text
038.
Catch
ex
As
Exception
039.
Console.WriteLine(ex.Message)
040.
Return
041.
End
Try
042.
043.
Query =
"select * from 社員マスタ"
044.
myCommand.CommandText = Query
045.
046.
047.
048.
049.
Try
050.
myReader = myCommand.ExecuteReader
051.
Catch
ex
As
Exception
052.
myCon.Close()
053.
Console.WriteLine(ex.Message)
054.
Return
055.
End
Try
056.
057.
058.
Dim
nCols
As
Integer
= myReader.FieldCount
059.
Dim
fldType
As
System.Type
060.
061.
062.
Dim
idx
As
Integer
063.
Do
While
myReader.Read()
064.
For
idx = 0
To
nCols - 1
065.
066.
if idx <> 0 then
067.
Console.Write(
","
)
068.
end if
069.
070.
071.
If
Not
myReader.IsDBNull(idx)
Then
072.
fldType = myReader.GetFieldType(idx)
073.
If
fldType.Name =
"String"
Then
074.
075.
Console.Write(myReader.GetValue(idx) +
""
)
076.
077.
ElseIf
fldType.Name =
"Int32"
Then
078.
079.
Console.Write(myReader.GetInt32(idx).ToString() +
""
)
080.
081.
ElseIf
fldType.Name =
"DateTime"
Then
082.
083.
Console.Write(myReader.GetDateTime(idx).ToString() +
""
)
084.
085.
Else
086.
087.
Console.Write(myReader.GetValue(idx).ToString() +
""
)
088.
089.
End
If
090.
Else
091.
Console.Write(
""
)
092.
End
If
093.
Next
094.
095.
Console.WriteLine(
""
)
096.
097.
Loop
098.
099.
100.
myReader.Close()
101.
102.
103.
104.
105.
106.
Query =
"update 社員マスタ set 生年月日 = '2000/01/01' where 生年月日 is NULL"
107.
myCommand.CommandText = Query
108.
Try
109.
myCommand.ExecuteNonQuery()
110.
Catch
ex
As
Exception
111.
myCon.Close()
112.
Console.WriteLine(ex.Message)
113.
Return
114.
End
Try
115.
116.
117.
118.
119.
myCon.Close()
120.
121.
End
Sub
122.
123.
End
Module