M
marcmc
I am a Csharp.NET developer with little or no exposure to VB.
I need to connect to a SQL database on a click event, read a number of cells
and insert/update/delete them from a SQL table.
Any guides where I can get help with the slightly different syntax.
Here is the code I want to transform:
Private Sub btnUpdate_Click()
Dim cn As SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand
Dim cmdSelect As New SqlClient.SqlCommand
Dim strSQL As String = "UPDATE mis_MISRE_employees SET Logged_In = 'Y'
WHERE uname = '" + UName + "' "
Dim cmdSelect As New SqlClient.SqlCommand
cmdSelect.CommandText = strSQL
cmdSelect.CommandType = CommandType.Text
Try
cn = New SqlClient.SqlConnection("user id=" & UNameLogXML &
";password=" & PasswordLogXML & ";database=" & DatabaseLogXML & ";server=" &
ServerLogXML)
cn.Open()
cmdSelect1.Connection = cn
cmdSelect1.ExecuteNonQuery()
Catch ex As Exception
sqlCnError = ("Error: Could not establish database connection")
End Try
cn.Close()
cn.Dispose()
End Sub
I need to connect to a SQL database on a click event, read a number of cells
and insert/update/delete them from a SQL table.
Any guides where I can get help with the slightly different syntax.
Here is the code I want to transform:
Private Sub btnUpdate_Click()
Dim cn As SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand
Dim cmdSelect As New SqlClient.SqlCommand
Dim strSQL As String = "UPDATE mis_MISRE_employees SET Logged_In = 'Y'
WHERE uname = '" + UName + "' "
Dim cmdSelect As New SqlClient.SqlCommand
cmdSelect.CommandText = strSQL
cmdSelect.CommandType = CommandType.Text
Try
cn = New SqlClient.SqlConnection("user id=" & UNameLogXML &
";password=" & PasswordLogXML & ";database=" & DatabaseLogXML & ";server=" &
ServerLogXML)
cn.Open()
cmdSelect1.Connection = cn
cmdSelect1.ExecuteNonQuery()
Catch ex As Exception
sqlCnError = ("Error: Could not establish database connection")
End Try
cn.Close()
cn.Dispose()
End Sub