Click here to Skip to main content
15,903,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
there is no parameter coming for mysqlcommand in WPF in .net..can u explain me the connection string in WPF application...
Posted
Updated 13-Mar-13 21:40pm
v2

1 solution

DbCommand[^] accepts only reference to your connection and command text (query). Optionally, you can create command from connection itself. Check my example:
C#
// Create MySql connection
using (var sqlConn = new MySqlConnection("your connection string"))
{
    // Open connection
    sqlConn.Open();

    // Create new command
    using (var cmd = sqlConn.CreateCommand())
    {
        // Set command text
        cmd.CommandText = "your sql query with @paramName";

        // Add command parameters
        cmd.Parameters.AddWithValue("@paramName", null);

        // Finally call *ONE* of these methods below:
        var numRows = cmd.ExecuteNonQuery(); // UPDATE/DELETE statement
        var value = cmd.ExecuteScalar(); // SELECT single value

        using (var reader = cmd.ExecuteReader()) // SELECT result set
        {
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    var colValue = reader.GetString(0);
                }
            }
        }
    }
}
 
Share this answer
 
Comments
premkumar12 14-Mar-13 4:57am    
ur answer suits for my doubt..thanks..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900