4 Replies - 486 Views - Last Post: 18 April 2011 - 07:00 AM Rate Topic: -----

#1 lauram340  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-April 11

Data Not Going into a Database

Posted 18 April 2011 - 03:57 AM

I have been trying to add data from a form into a database.
The database is called Pipelining and within that there is a table called questions
There is no error that is coming up, but the information isn't going into the database. I was wondering if anyone would be able to help me with this and see if they can see why its not doing it?
I have breakpointed it and stepped through it but I am unable to see whats going on

Thank you for your time

  Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim Cmd As OleDbCommand
        Dim SQL As String
        Dim objCmd As OleDbCommand
        Dim Con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=pipelining.mdb;Persist Security Info=False")
        Dim question As String = txtQuestion.Text
        Dim answer1 As String = txtAnswer1.Text
        Dim answer2 As String = txtAnswer2.Text
        Dim answer3 As String = txtAnswer3.Text
        Dim answer4 As String = txtAnswer4.Text
        Dim answer5 As String = txtAnswer5.Text
        Dim correctAnswer As String = txtCorrectAnswer1.Text
        Dim correctAnswer2 As String = txtCorrectAnswer2.Text


        SQL = "INSERT INTO questions VALUES ('" & question & "', '" & answer1 & "', '" & answer2 & "', '" & answer3 & "', '" & answer4 & "', '" & answer5 & "', '" & correctAnswer & "', '" & correctAnswer2 & "')"

        Cmd = New OleDbCommand(SQL, Con)

        Con.Open()
        objCmd = New OleDbCommand(SQL, Con)
        objCmd.ExecuteNonQuery()
        Con.Close()
        MessageBox.Show("Data Added")
        formalQuiz.Show()
        Me.Hide()

    End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Data Not Going into a Database

#2 ericzmeh  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 56
  • Joined: 13-September 09

Re: Data Not Going into a Database

Posted 18 April 2011 - 05:00 AM

I have never done SQL injection using VB before, but these statements may be holding you back:

Change this:
Cmd = New OleDbCommand(SQL, Con)

      Con.Open()
      objCmd = New OleDbCommand(SQL, Con)
      objCmd.ExecuteNonQuery()



To This:

Con.Open()
Cmd = New OleDbCommand(SQL, Con)
      objCmd = New OleDbCommand(SQL, Con)
      objCmd.ExecuteNonQuery()



Maybe that could help?
Also, I'm not sure what you are doing here?

MessageBox.Show("Data Added")
      formalQuiz.Show()



What type of objejct is formalQuiz? I don't see it declared? Hope this helps :-]
Was This Post Helpful? 0
  • +
  • -

#3 lauram340  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-April 11

Re: Data Not Going into a Database

Posted 18 April 2011 - 05:07 AM

View Postericzmeh, on 18 April 2011 - 05:00 AM, said:

I have never done SQL injection using VB before, but these statements may be holding you back:

Change this:
Cmd = New OleDbCommand(SQL, Con)

      Con.Open()
      objCmd = New OleDbCommand(SQL, Con)
      objCmd.ExecuteNonQuery()



To This:

Con.Open()
Cmd = New OleDbCommand(SQL, Con)
      objCmd = New OleDbCommand(SQL, Con)
      objCmd.ExecuteNonQuery()



Maybe that could help?
Also, I'm not sure what you are doing here?

MessageBox.Show("Data Added")
      formalQuiz.Show()



What type of objejct is formalQuiz? I don't see it declared? Hope this helps :-]


sorry, i forgot to say formalquiz is another form :) Messagebox was just for me to see if the code was working :)

It is now working and calling it but once I close the program too see if the data has been added for good, its not turning up :S
Was This Post Helpful? 0
  • +
  • -

#4 ericzmeh  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 56
  • Joined: 13-September 09

Re: Data Not Going into a Database

Posted 18 April 2011 - 05:42 AM

Your close() method is stated before you show your message box:


Con.Open()
      objCmd = New OleDbCommand(SQL, Con)
      objCmd.ExecuteNonQuery()
      Con.Close()
      MessageBox.Show("Data Added")
      formalQuiz.Show()
      Me.Hide()



Could that be holding you back?
Try this:

Con.Open()
      objCmd = New OleDbCommand(SQL, Con)
      objCmd.ExecuteNonQuery()
      MessageBox.Show("Data Added")
      formalQuiz.Show()
      Me.Hide()
Con.Close()


Was This Post Helpful? 0
  • +
  • -

#5 lauram340  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-April 11

Re: Data Not Going into a Database

Posted 18 April 2011 - 07:00 AM

Tried that before and it didn't work. hmmmm....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1