Store data into Access

G

Guest

Hi,

I have a small table in an Access database, each record has 3 fields. I want to store 3 values into a record. I looked at the view SQL in Access and saw the following:

INSERT INTO Loaded_Tables ( TableName, Date_Added, [Rows] )
SELECT "abc" AS Expr1, Now() AS Expr2, 100 AS Expr3;

So I guess I can just use this SQL in a OleDbCommand.

Is there a better way to do this? I just found out about DataRows by reading some answers in this discussion area -- is that a good way to do it? If so, I don't know how one stores a DataRow in an Access Table.

I'd appreciate any help.

Thanks,

Art
 
C

Cor Ligthert

Art,

Are you using a dataset/table, because you are talking about Datarows.

This method you show is probably just to store values in a database by
instance using the command.executenonQuery

When you use a dataadapter and a dataset, you can as well use the
commandbuilder for such insert, delete and update commands, so tell us how
you do retrieve your data.

Cor
I have a small table in an Access database, each record has 3 fields. I
want to store 3 values into a record. I looked at the view SQL in Access
and saw the following:
INSERT INTO Loaded_Tables ( TableName, Date_Added, [Rows] )
SELECT "abc" AS Expr1, Now() AS Expr2, 100 AS Expr3;

So I guess I can just use this SQL in a OleDbCommand.

Is there a better way to do this? I just found out about DataRows by
reading some answers in this discussion area -- is that a good way to do it?
If so, I don't know how one stores a DataRow in an Access Table.
 
C

Cor Ligthert

Hi Art,

Untested written in a notepad while copying from a everywhere.

I hope this helps?
And when it is not clear feel free to reply

Cor

\\\
Private cmd as OleDb.OledbCommand
Dim conn As New Data.OleDb.OleDbConnection
=("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="C:\something")
Private Sub AddToLog
conn.Open
cmd.CommandText = "INSERT INTO Logfile (Field1, Field2, Field3)" & _
" VALUES (@Field1, @Field2, @Field3')"
Dim p1 As OleDb.OleDbParameter = cmd.Parameters.Add("@Field1",
OleDb.OleDbType.VarWchar)
Dim p2 As OleDb.OleDbParameter = cmd.Parameters.Add("@Field1",
OleDb.OleDbType.VarWchar)
Dim p3 As OleDb.OleDbParameter = cmd.Parameters.Add("@Field1",
OleDb.OleDbType.VarWchar)
p1.Value = myfield1
p2.Value = myfield2
p3.Value = myfield3
doCmd(cmd)
conn.Close()
End Sub
Private Sub doCmd(ByVal cmd As Data.OleDb.OleDbCommand)
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
End Sub
///
 
C

Cor Ligthert

I forgot to write, the logfile should have in this way an autoincrement
field as primary key.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top