Jump to content

Need VB and database help

- - - - -

  • Please log in to reply
3 replies to this topic

#1
graphicsman

graphicsman

    Newbie

  • Members
  • PipPip
  • 21 posts
My final project is due next Tuesday for my VB course. We were just introduced to databases with VB but i figured out how to get on to work in my form. Only problem is i cant figure out how or where to go to get a text box to update the database after a button click. I also need a button to remove and edit the row in the database. Ideas would be great.

#2
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 405 posts
I assume you are using some version of visual studio. When you create a windows forms application type. It opens up a form page, on the left of which you can click, choose, drag and drop any control such as button, text box etc. to your main UI (appearing as form designer). After this if you want to for e.g. add code to the button, double clicking on the button will take you into a code window automatically generated against this form inside button's clicked function. What ever code you write inside that function will execute when the button is clicked.

Same applies to any other control

#3
Zvone

Zvone

    Newbie

  • Members
  • Pip
  • 3 posts
If you use SQLServer 2008R2 might this help you:

Update the database
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        sqlLink = New SqlConnection()

        sqlLink.ConnectionString = "Data Source=Admin-PC\SQLEXPRESS;Initial Catalog=DatabaseName;User ID=Something;Password=Something"  '//Enter your data for SQLServer

        Try

            sqlLink.Open()

            Dim sqlOrder As New SqlCommand()

            sqlOrder.Connection = sqlLink

            sqlOrder.CommandText = "INSERT INTO TableName(ColumnName1,ColumnName2) " &

                                   "VALUES('" & txtColumnName1.Text & "','" & txtColumnName2.Text & "')"

            sqlOrder.ExecuteNonQuery()

        Catch EX As Exception

            MsgBox("An error occurred: " & EX.Message)

        Finally

            sqlLink.Close()

        End Try

    End Sub

Remove the row
Private Sub btnRowsRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRowsRemove.Click

        DataGridView1.Rows.RemoveAt(0)

    End Sub


#4
edge02

edge02

    Newbie

  • Members
  • PipPip
  • 21 posts
you failed to mention what database your using and are you using
and if you are using windows form application.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users