Link to home
Start Free TrialLog in
Avatar of MrTV
MrTVFlag for Thailand

asked on

c# connect to mysql databae

How many method that c# connect to my sql  odbc , .net and what is the difference
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>  The difference between the two

The difference between the THREE   :)
ADO.NET is the best and allows you to create mulitple join statements, whereas ODBC, and OLEDB you can only hit one table at a time...

Plus with ADO.NET you have use of parameters which prevents SQL injection and the dataaptor lets you easily find data that you just quried....its really a step up...

example of parameters to prevent sql injection

Dim SQLstring As String = "SELECT * FROM PRODUCT p Join customer c ON  c.id = p.id WHERE WxxD = @var_xxIxt_ID AND 1 = 1"

 Using command As New SqlCommand(SQLstring, sqlConn)
    command.Parameters.Add(New SqlParameter("@var_xxIxt_ID", SqlDbType.Int)).Value = var_xxIxT_ID
    dataReader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    If dataReader.HasRows Then
        Do While dataReader.Read()


with the old stuff I would add " AND 1 = 1 " as a trick to prevent sql injection...