By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Store data into Access

P: n/a
Art
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
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
I'd appreciate any help.

Thanks,

Art

Nov 20 '05 #2

P: n/a
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
///
Nov 20 '05 #3

P: n/a
I forgot to write, the logfile should have in this way an autoincrement
field as primary key.

Cor
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.