List Info

Thread: Re: Need VB 2005 snippet of code for inserting row into MS Access 2003




Re: Need VB 2005 snippet of code for inserting row into MS Access 2003
country flaguser name
United States
2008-05-23 09:32:17

CJ,

I think I need more help. I am having difficulty tying your
connnectionobject to my code. Please let me explain my steps.

- I created a console application, then chose data, add datasource,
database, new connection.

- datasource: Microsoft Access Database file

- Database filename = c:datatest.mdb

- Connectionstring = Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:datatest.MDB

- Save connection as: testConnectionstring

- dataset name = testDataSet

- tablename = newtable, field = FieldA with
Dim FieldA as integer

Can you please give me the complete Dim statement with how your
syntax "connectionobject relates to the above code that was
generated with the wizard above.

Thank you,

- larryTAKEOUT%40seldin.net">larryTAKEOUTseldin.net

--- In VisualBasic_Official%40yahoogroups.com">VisualBasic_Officialyahoogroups.com, Chris Judge
<cjudge1966...> wrote:

SQL = "INSERT NewTable SET FieldA = '" & newvalue & "'&quot;
connectionobject.Execute(SQL)

__._,_.___
.

__,_._,___
Re: Need VB 2005 snippet of code for inserting row into MS Access 2003
country flaguser name
United States
2008-05-23 17:09:40

Larry,

In my first reply, the example I gave was for the
ADODB connection object under VB6. I noticed this
time that your subject line states VB 2005. I
apologize for any confusion I caused.

I don't use the wizards. The basic sequence in VB.Net
is as follows:

1. Create a SqlConnection object.

2. Set the SqlConnection object's ConnectionString
property.

3. Call the SqlConnection object's Open method.

4. Create a SqlCommand object via the SqlConnection
object's CreateCommand method.

5. Set the SqlCommand object's CommandText property to
the SQL command(s) you wish to execute.

6. As I recall, you wanted to insert a new record -
i.e. your SQL command will not return records - so you
then call the SqlCommand object's ExecuteNonQuery
method to run your SQL command.

7. Set the SqlCommand object to Nothing.

8. Call the SqlConnection object's Close method.

9. Set the SqlConnection object to nothing.

In code (without all the Try..Catch blocks that you
should include):

Imports System.Data.SqlClient
...
Dim Connection As New SqlConnection

Connection.ConnectionString = yourconnectionstring

Connection.Open()

Dim Command As SqlCommand = Connection.CreateCommand()

Command.CommandText = yoursqlcommand

Command.ExecuteNonQuery()

Command = Nothing

Connection.Close

Connection = Nothing

cj

--- lseldin < larry%40seldin.net">larryseldin.net> wrote:

> CJ,
>
> I think I need more help. I am having difficulty
> tying your
> connnectionobject to my code. Please let me explain
> my steps.
&gt;
> - I created a console application, then chose data,
&gt; add datasource,
> database, new connection.
>
> - datasource: Microsoft Access Database file
>;
> - Database filename = c:datatest.mdb
>;
> - Connectionstring =
> Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=C:datatest.MDB
>
> - Save connection as: testConnectionstring
>
> - dataset name = testDataSet
>
> - tablename = newtable, field = FieldA with
>; Dim FieldA as integer
>
>
> Can you please give me the complete Dim statement
> with how your
> syntax "connectionobject relates to the above code
>; that was
> generated with the wizard above.
&gt;
> Thank you,
>;
> - larryTAKEOUT%40seldin.net">larryTAKEOUTseldin.net
>
>
>
> --- In VisualBasic_Official%40yahoogroups.com">VisualBasic_Officialyahoogroups.com, Chris
&gt; Judge
> <cjudge1966...> wrote:
&gt;
> SQL = "INSERT NewTable SET FieldA = '" & newvalue &
&gt; "'&quot;
> connectionobject.Execute(SQL)
>
>
>

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )