Click here to Skip to main content
15,902,938 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Is there any library to compare 2 sql server databases ? Pin
Chris Quinn27-Jul-15 2:12
Chris Quinn27-Jul-15 2:12 
GeneralRe: Is there any library to compare 2 sql server databases ? Pin
satc27-Jul-15 2:43
satc27-Jul-15 2:43 
GeneralRe: Is there any library to compare 2 sql server databases ? Pin
Chris Quinn27-Jul-15 3:59
Chris Quinn27-Jul-15 3:59 
GeneralRe: Is there any library to compare 2 sql server databases ? Pin
satc27-Jul-15 4:07
satc27-Jul-15 4:07 
GeneralRe: Is there any library to compare 2 sql server databases ? Pin
Sascha Lefèvre27-Jul-15 4:31
professionalSascha Lefèvre27-Jul-15 4:31 
GeneralRe: Is there any library to compare 2 sql server databases ? Pin
satc27-Jul-15 19:48
satc27-Jul-15 19:48 
QuestionCrazy ODBCDataReader Pin
Marcus Genovese24-Jul-15 4:12
Marcus Genovese24-Jul-15 4:12 
AnswerRe: Crazy ODBCDataReader Pin
Richard Deeming24-Jul-15 4:49
mveRichard Deeming24-Jul-15 4:49 
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

You're executing your command twice - once to fill a DataTable, which you then throw away, and once with the ExecuteReader method.

You've then tried to access columns from the returned OdbcDataReader object without first calling its Read method. This will throw an exception.

Your query is selecting multiple rows from the table, but you're only using the first row. You should change it to only select a single row instead.

You're using SELECT * FROM ..., which returns every column in the table. You're then only using two columns. Change your query to return only the columns you need.

You should also wrap any objects that implement IDisposable in a Using block.
VB.NET
Private Sub txtPaese_Leave_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPaese.Leave
    Try
        Using cn As New OdbcConnection("dsn=PHOENIXDB;uid=SYSDBA;pwd=masterkey;")
            
            ' TODO: Only select the columns you're going to use.
            Dim query As String = "SELECT TOP 1 * FROM TBL_COMUNI WHERE COMUNE = ?"
            
            Using cmd As New OdbcCommand(query, cn)
                
                ' ODBC doesn't use named parameters, so only the order matters here:
                cmd.Parameters.AddWithValue("p0", txtPaese.Text)
                
                ' No need for the DataSet / OdbcDataAdapter code here,
                ' since you're not using the loaded data anyway.
                
                cn.Open()
                
                Using reader As OdbcDataReader = cmd.ExecuteReader(CommandBehiavor.CloseConnection)
                    If reader.Read() Then
                        ' TODO: Update the column index when you change the query,
                        '       or use the column name instead.
                        Me.txtCAP.Text = reader.Item(11)
                        Me.txtPR.Text = reader.Item(4)
                    Else
                        ' TODO: The record was not found. Tell the user.
                    End If
                End Using
            End Using
        End Using
        
    Catch ex As Exception
        MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
    End Try
End Sub




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Crazy ODBCDataReader Pin
Marcus Genovese24-Jul-15 5:25
Marcus Genovese24-Jul-15 5:25 
QuestionHow to write Worksheet Change Event in Visual Studio 2010??? Pin
Member 1184098123-Jul-15 21:27
Member 1184098123-Jul-15 21:27 
QuestionOracleDataReader GetChars method only buffering half the characters Pin
Aaron Rosenthal22-Jul-15 12:48
Aaron Rosenthal22-Jul-15 12:48 
AnswerRe: OracleDataReader GetChars method only buffering half the characters Pin
Eddy Vluggen22-Jul-15 23:33
professionalEddy Vluggen22-Jul-15 23:33 
GeneralRe: OracleDataReader GetChars method only buffering half the characters Pin
Aaron Rosenthal23-Jul-15 2:03
Aaron Rosenthal23-Jul-15 2:03 
GeneralRe: OracleDataReader GetChars method only buffering half the characters Pin
Eddy Vluggen23-Jul-15 2:13
professionalEddy Vluggen23-Jul-15 2:13 
AnswerRe: OracleDataReader GetChars method only buffering half the characters Pin
Richard Deeming23-Jul-15 2:20
mveRichard Deeming23-Jul-15 2:20 
GeneralRe: OracleDataReader GetChars method only buffering half the characters Pin
Aaron Rosenthal23-Jul-15 3:36
Aaron Rosenthal23-Jul-15 3:36 
GeneralRe: OracleDataReader GetChars method only buffering half the characters Pin
Richard Deeming23-Jul-15 3:56
mveRichard Deeming23-Jul-15 3:56 
GeneralRe: OracleDataReader GetChars method only buffering half the characters Pin
Aaron Rosenthal23-Jul-15 4:24
Aaron Rosenthal23-Jul-15 4:24 
GeneralRe: OracleDataReader GetChars method only buffering half the characters Pin
Richard Deeming23-Jul-15 4:51
mveRichard Deeming23-Jul-15 4:51 
GeneralRe: OracleDataReader GetChars method only buffering half the characters Pin
Aaron Rosenthal23-Jul-15 6:11
Aaron Rosenthal23-Jul-15 6:11 
GeneralRe: OracleDataReader GetChars method only buffering half the characters Pin
Richard Deeming23-Jul-15 6:20
mveRichard Deeming23-Jul-15 6:20 
GeneralRe: OracleDataReader GetChars method only buffering half the characters Pin
Aaron Rosenthal23-Jul-15 6:24
Aaron Rosenthal23-Jul-15 6:24 
SuggestionRe: OracleDataReader GetChars method only buffering half the characters Pin
Richard Deeming23-Jul-15 6:25
mveRichard Deeming23-Jul-15 6:25 
AnswerRe: OracleDataReader GetChars method only buffering half the characters Pin
Richard Deeming23-Jul-15 6:37
mveRichard Deeming23-Jul-15 6:37 
GeneralRe: OracleDataReader GetChars method only buffering half the characters Pin
Aaron Rosenthal23-Jul-15 8:02
Aaron Rosenthal23-Jul-15 8:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.