Click here to Skip to main content
15,904,023 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questionlinking multiple tables(3 or more tables) using sql select query in vb6 Pin
Member 102487687-Feb-14 0:32
Member 102487687-Feb-14 0:32 
AnswerRe: linking multiple tables(3 or more tables) using sql select query in vb6 Pin
Dave Kreskowiak7-Feb-14 7:44
mveDave Kreskowiak7-Feb-14 7:44 
AnswerRe: linking multiple tables(3 or more tables) using sql select query in vb6 Pin
Tim Carmichael7-Feb-14 7:53
Tim Carmichael7-Feb-14 7:53 
SuggestionRe: linking multiple tables(3 or more tables) using sql select query in vb6 Pin
Mycroft Holmes8-Feb-14 13:25
professionalMycroft Holmes8-Feb-14 13:25 
GeneralRe: linking multiple tables(3 or more tables) using sql select query in vb6 Pin
SoMad8-Feb-14 13:53
professionalSoMad8-Feb-14 13:53 
GeneralRe: linking multiple tables(3 or more tables) using sql select query in vb6 Pin
Mycroft Holmes8-Feb-14 16:23
professionalMycroft Holmes8-Feb-14 16:23 
GeneralRe: linking multiple tables(3 or more tables) using sql select query in vb6 Pin
Eddy Vluggen8-Feb-14 23:58
professionalEddy Vluggen8-Feb-14 23:58 
QuestionInsert ComboBox records into SQL table Pin
Gentry_386-Feb-14 12:34
Gentry_386-Feb-14 12:34 
I have multiple combobox which pulls all its information from several sql tables. The records are being populated but unable to insert into a sql table (tran_log) once data's are selected. I found a scripts which prompts me that I have a successful connection to my DB and that an insert has been made but the records are not being updated. I tried 2 different scripts but still no luck. Also, I get an error regarding objcmd.ExecuteNonQuery() from both scripts that's why its commented. Thanks!

Script 1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim acsconn As OleDbConnection = New OleDbConnection _
    ("provider=SQLOLEDB;data source=DBserver;database=myDB;user ID=user;password=mypassword;")
    acsconn.Open()
    If acsconn.State = ConnectionState.Open Then
        MsgBox("Connected")

        Dim strsql As String = "insert into tran_log(hw_name,[type],[status],wh_function,[user],check_out_date)values(?,?,?,?,?,?);"

        Dim objcmd As New System.Data.OleDb.OleDbCommand(strsql, acsconn) ' the oledbcommand

        With objcmd
            .Parameters.AddWithValue("@ComboBox1", ComboBox1.SelectedItem)
            .Parameters.AddWithValue("@TextBox1", TextBox1.SelectedText)
            .Parameters.AddWithValue("@ComboBox2", ComboBox2.SelectedItem)
            .Parameters.AddWithValue("@ComboBox3", ComboBox3.SelectedItem)
            .Parameters.AddWithValue("@ComboBox4", ComboBox4.SelectedItem)
            .Parameters.AddWithValue("@DateTimePicker1", DateTimePicker1)


        End With
        Try
            objcmd.Connection.Open()
            Dim rowsAffected As Integer = objcmd.ExecuteNonQuery()
            Console.WriteLine("RowsAffected: {0}", rowsAffected)

        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try

        'objcmd.ExecuteNonQuery()
        objcmd.Dispose()
        MsgBox("Saved")

    End If
    acsconn.Close()
End Sub


Script 2:
VB
Dim strcom1 As String = ComboBox1.SelectedText
       Dim strcom2 As String = TextBox1.SelectedText
       Dim strcom3 As String = ComboBox2.SelectedText
       Dim strcom4 As String = ComboBox3.SelectedText
       Dim strcom5 As String = ComboBox4.SelectedText
       Dim strcom6 As New DateTimePicker()

       Dim objconnection As OleDb.OleDbConnection = Nothing
       Dim objcmd As OleDb.OleDbCommand = Nothing
       Dim strconnection As String, strSQL As String


       'connection string
       strconnection = "provider=SQLOLEDB;data source=DBserver;database=myDB;user ID=user;password=mypassword;"

       objconnection = New OleDb.OleDbConnection(strconnection)
       objconnection.ConnectionString = strconnection
       objconnection.Open()

       strSQL = "insert into tran_log(hw_name,[type],[status],wh_function,[user],check_out_date)values(@ComboBox1,@TextBox1,@ComboBox2,@ComboBox3,@ComboBox4,@DateTimePicker);"
       objcmd = New OleDb.OleDbCommand(strSQL, objconnection)
       objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@ComboBox1", strcom1))
       objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@TextBox1", strcom2))
       objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@ComboBox2", strcom3))
       objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@ComboBox3", strcom4))
       objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@ComboBox4", strcom5))
       objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@DateTimePicker", strcom6))
       'objcmd.ExecuteNonQuery()

       'close connection
       objconnection.Close()
       MessageBox.Show("Entered Successfully!")

AnswerRe: Insert ComboBox records into SQL table Pin
Richard Deeming7-Feb-14 1:41
mveRichard Deeming7-Feb-14 1:41 
GeneralRe: Insert ComboBox records into SQL table Pin
Gentry_387-Feb-14 10:12
Gentry_387-Feb-14 10:12 
GeneralRe: Insert ComboBox records into SQL table Pin
Richard Deeming7-Feb-14 10:48
mveRichard Deeming7-Feb-14 10:48 
GeneralRe: Insert ComboBox records into SQL table Pin
Gentry_388-Feb-14 10:06
Gentry_388-Feb-14 10:06 
QuestionSavefieldialog and Folderbrowserdialog Pin
Tsunamipudip5-Feb-14 17:51
Tsunamipudip5-Feb-14 17:51 
AnswerRe: Savefieldialog and Folderbrowserdialog Pin
Richard MacCutchan5-Feb-14 22:42
mveRichard MacCutchan5-Feb-14 22:42 
Questionexporting vb6 data from ms access to PDF using sql select query Pin
Member 102487684-Feb-14 20:39
Member 102487684-Feb-14 20:39 
AnswerRe: exporting vb6 data from ms access to PDF using sql select query Pin
Chris Quinn4-Feb-14 20:48
Chris Quinn4-Feb-14 20:48 
GeneralRe: exporting vb6 data from ms access to PDF using sql select query Pin
Member 102487684-Feb-14 21:49
Member 102487684-Feb-14 21:49 
GeneralRe: exporting vb6 data from ms access to PDF using sql select query Pin
Chris Quinn5-Feb-14 4:52
Chris Quinn5-Feb-14 4:52 
QuestionMany questions on a VB Project using DOS command. Pin
Member 105704213-Feb-14 23:20
Member 105704213-Feb-14 23:20 
AnswerRe: Many questions on a VB Project using DOS command. Pin
Richard Deeming4-Feb-14 3:01
mveRichard Deeming4-Feb-14 3:01 
GeneralRe: Many questions on a VB Project using DOS command. Pin
Member 105704214-Feb-14 5:57
Member 105704214-Feb-14 5:57 
AnswerRe: Many questions on a VB Project using DOS command. Pin
Eddy Vluggen4-Feb-14 3:01
professionalEddy Vluggen4-Feb-14 3:01 
AnswerRe: Many questions on a VB Project using DOS command. Pin
Dave Kreskowiak4-Feb-14 4:01
mveDave Kreskowiak4-Feb-14 4:01 
QuestionDataGridView that use timer in vb.net Pin
Joannou H. Fegarido3-Feb-14 14:20
Joannou H. Fegarido3-Feb-14 14:20 
AnswerRe: DataGridView that use timer in vb.net Pin
Eddy Vluggen4-Feb-14 7:51
professionalEddy Vluggen4-Feb-14 7:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.