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.
3 replies to this topic
#1
Posted 19 May 2011 - 07:08 AM
|
|
|
#2
Posted 19 May 2011 - 10:38 AM
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
Same applies to any other control
#3
Posted 21 May 2011 - 10:50 AM
If you use SQLServer 2008R2 might this help you:
Update the database
Remove the row
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
Posted 23 August 2011 - 02:02 AM
you failed to mention what database your using and are you using
and if you are using windows form application.
and if you are using windows form application.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









