Help with an SQL Statement

B

Brad Markisohn

I'm modifying a VB.Net application that uses an Access DB for parameter and
data storage. I've had to make a DB schema change and, in order to maintain
backwards comapatibility, I would like to add a new row to a specific table
in the DB if it doesn't exist. I'm using an OLEDABConnection object, but
I'm not familiar enough with SQL to know the verbiage to add the new row.
Can any body help me with this? Here's a snipit of the code:

Public Sub InsertARow()
Dim myConnection As New OleDbConnection(mstrConnectionString)
Dim myInsertQuery As String = QUERY TO ADD ROW GOES HERE
Dim myCommand As New OleDbCommand(myInsertQuery)

myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()

TIA

Brad
 
C

Cor Ligthert

Brad,

I think that with this peace of code beneath you are far on your way.

However for this question is the newsgroup beneath mostly a better place
Adonet
news://msnews.microsoft.com/microsoft.public.dotnet.framework.adonet
Web interface:
http://communities2.microsoft.com/c.../?dg=microsoft.public.dotnet.framework.adonet

I hope this helps?

Cor

\\\
Dim conn As New
Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source="mydatabase.Mdb")
conn.Open()
Dim cmd As New OleDb.OleDbCommand("ALTER TABLE Persons " & _
"ADD Instant NVarchar(20)", conn)
doCmd(cmd)
conn.Close()
End Sub
Private Sub doCmd(ByVal cmd As Data.OleDb.OleDbCommand)
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
If ex.ErrorCode = -2147217887 Then Exit Sub
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
End Sub
///
 
B

Brad Markisohn

Cor,

Thanks for the assistance. I still need a little help with SQL specifics,
but this set me on the right track.

Brad
 

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