RAFOO
Member
- Joined
- Jun 6, 2024
- Messages
- 6
- Programming Experience
- 10+
Sorry to disturb you.
I continue learning, and now I want to work with SQL Server on Visual Studio 2022.
I already made a small project; I create as well a Database via SSMS and on Visual Studio on left Tab Server Explorer the server / Database / Tables are visible after a successful connection.
On a Form I have a TextBox with a text and I want to update the Database with this content, I have no problems with any kind of SQL Language but, I need a little help to start coding to read and write from and to the Database-Table.
Can you please send me a small code part with main aspects on how to do it, starting with “imports”.
I was used to make like this sample below but it does not work! The underline part gives Error.
Thanks and sorry again.
-----------------------------------------------------------------------------------------
Imports ????
Public Class frmTipo
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connectionString As String = Server = RAFOO\SQLEXPRESS;Database=ASFITA;Trusted_Connection=True"
Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection(connectionString)
Dim cmd As New System.Data.SqlClient.SqlCommand
cmd.CommandType = System.Data.CommandType.Text
cmd.CommandText = "INSERT Tipos (Tipo) VALUES (" + txtTipo.text + ")"
cmd.Connection = sqlConnection1
sqlConnection1.Open()
cmd.ExecuteNonQuery()
sqlConnection1.Close()
End Sub
End Class
I continue learning, and now I want to work with SQL Server on Visual Studio 2022.
I already made a small project; I create as well a Database via SSMS and on Visual Studio on left Tab Server Explorer the server / Database / Tables are visible after a successful connection.
On a Form I have a TextBox with a text and I want to update the Database with this content, I have no problems with any kind of SQL Language but, I need a little help to start coding to read and write from and to the Database-Table.
Can you please send me a small code part with main aspects on how to do it, starting with “imports”.
I was used to make like this sample below but it does not work! The underline part gives Error.
Thanks and sorry again.
-----------------------------------------------------------------------------------------
Imports ????
Public Class frmTipo
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connectionString As String = Server = RAFOO\SQLEXPRESS;Database=ASFITA;Trusted_Connection=True"
Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection(connectionString)
Dim cmd As New System.Data.SqlClient.SqlCommand
cmd.CommandType = System.Data.CommandType.Text
cmd.CommandText = "INSERT Tipos (Tipo) VALUES (" + txtTipo.text + ")"
cmd.Connection = sqlConnection1
sqlConnection1.Open()
cmd.ExecuteNonQuery()
sqlConnection1.Close()
End Sub
End Class