Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,086 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,537 people online right now. Registration is fast and FREE... Join Now!




Simple separated sql question

 
Reply to this topicStart new topic

Simple separated sql question

itayzoro
25 Aug, 2008 - 01:23 AM
Post #1

New D.I.C Head
*

Joined: 29 Jul, 2008
Posts: 20

How can i insert into field more then 1 data ???
If i try to use comma the data is insert into the next field and i want only feed Field1 with more then 1 record
or i cant fill with 1 sql statment and i need 1 stament for each record
i need somthing like "LineFeed" or "Enter"


CODE

Dim dbFileNew As String = "C:\Dest.mdb"
        sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbFileNew

    
        SQL24 = "INSERT INTO Table1 (Field1) VALUES(3)"
        Dim Sconn As New System.Data.OleDb.OleDbConnection(sConnectionString)
        Dim cmd24 As New System.Data.OleDb.OleDbCommand(SQL24, Sconn)
        Dim dr24 As System.Data.OleDb.OleDbDataReader
        Sconn.Open()
        dr24 = cmd24.ExecuteReader()
        dr24.Read()
        dr24.Close()
        Sconn.Close()

User is offlineProfile CardPM
+Quote Post

dineeshd
RE: Simple Separated Sql Question
25 Aug, 2008 - 02:06 AM
Post #2

D.I.C Addict
Group Icon

Joined: 30 Jun, 2008
Posts: 578



Thanked: 16 times
Dream Kudos: 575
My Contributions
Make this change and check.... rolleyes.gif
VB
SQL24 = "INSERT INTO Table1 (Field1) VALUES(3)   INSERT INTO Table1 (Field1) VALUES(4)   INSERT INTO Table1 (Field1) VALUES(5)"


User is offlineProfile CardPM
+Quote Post

itayzoro
RE: Simple Separated Sql Question
25 Aug, 2008 - 02:27 AM
Post #3

New D.I.C Head
*

Joined: 29 Jul, 2008
Posts: 20

QUOTE(dineeshd @ 25 Aug, 2008 - 03:06 AM) *

Make this change and check.... rolleyes.gif
VB
SQL24 = "INSERT INTO Table1 (Field1) VALUES(3)   INSERT INTO Table1 (Field1) VALUES(4)   INSERT INTO Table1 (Field1) VALUES(5)"



hi dineeshd and 10nx alot for the Reply wub.gif

But its not work i even try with ";"
User is offlineProfile CardPM
+Quote Post

dineeshd
RE: Simple Separated Sql Question
25 Aug, 2008 - 04:02 AM
Post #4

D.I.C Addict
Group Icon

Joined: 30 Jun, 2008
Posts: 578



Thanked: 16 times
Dream Kudos: 575
My Contributions
Acutally MS Access will not support multiple line insert using a single statement where SQL Server does.
Still I can suggest you a workaround for this. Use the below function.

vb
Public Sub AccessInsert(ByVal strFieldName As String, ByVal strField As String, ByVal strTable As String, ByVal objConn As System.Data.OleDb.OleDbConnection)
Try
Dim strSQL As String
strSQL = "INSERT INTO [" & strTable & "] (" & strFieldName & ") VALUES ('" & strField & "')"
objConn.Open()
Dim objCmd As New System.Data.OleDb.OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
objConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If objConn.State <> ConnectionState.Closed Then
objConn.Close()
End If
End Try
End Sub


And write multiple lines like this...

vb
AccessInsert("Field1", "3", "Table1", Sconn)
AccessInsert("Field1", "4", "Table1", Sconn)


Or even you can use a loop here...

Hope this helps.... rolleyes.gif
User is offlineProfile CardPM
+Quote Post

itayzoro
RE: Simple Separated Sql Question
25 Aug, 2008 - 04:42 AM
Post #5

New D.I.C Head
*

Joined: 29 Jul, 2008
Posts: 20

First Wooooow its work like Magic (not Johnson)
Second from now on I LOVE CATS


rolleyes.gif


10nx a lot man u save my day
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 08:09PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month