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">larry
seldin.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.
>
> - 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">larryTAKEOUT
seldin.net
>
>
>
> --- In VisualBasic_Official%40yahoogroups.com">VisualBasic_Official
yahoogroups.com, Chris
> Judge
> <cjudge1966
...> wrote:
>
> SQL = "INSERT NewTable SET FieldA = '" & newvalue &
> "'"
> connectionobject.Execute(SQL)
>
>
>
.