Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
private async void SectionASubmit_Clicked ( object    sender, 
                                            EventArgs e )
  {
  try
    {
    SignalDetails   deserialized = new SignalDetails ( );

    MySqlConnection mySqlConnection = new MySqlConnection ( 
                                            "Server=sql6.freesqldatabase.com;" + 
                                            "Port=3306;" +
                                            "database=sql6407915;" +
                                            "User Id=sql6407915;" +
                                            "Password=Telliant@123;" +
                                            "charset=utf8" );

    if ( mySqlConnection.State == ConnectionState.Closed )
      {
      MySqlCommand cmd;
      string       query = String.Empty;

      mySqlConnection.Open ( );
      query = "INSERT INTO SignalDetails ( Action, " +
                                          "Object, " +
                                          "Buyat, " +
                                          "TP1, " +
                                          "TP2, " +
                                          "SL, " +
                                          "isActive ) " +  
                                 "VALUES ( @Action, " +
                                          "@Object, " +
                                          "@Buyat, " +
                                          "@TP1, " +
                                          "@TP2, " +
                                          "@SL, " +
                                          "@isActive)";

      cmd = new MySqlCommand ( query, mySqlConnection );
      cmd.Parameters.AddWithValue ( "@ticker", deserialized.Action );
      cmd.Parameters.AddWithValue ( "@bid", deserialized.Object );
      cmd.Parameters.AddWithValue ( "@ask", deserialized.Buyat );
      cmd.Parameters.AddWithValue ( "@open", deserialized.TP1 );
      cmd.Parameters.AddWithValue ( "@low", deserialized.TP2 );
      cmd.Parameters.AddWithValue ( "@high", deserialized.SL );
      cmd.Parameters.AddWithValue ( "@isActive", "true" );
      cmd.ExecuteNonQuery ( );
      cmd.Parameters.Clear ( );
      cmd.Connection.Close ( );
      }
    DisplayAlert ( "Success", "Signal Send Successfully", "ok" );
    await Navigation.PushAsync ( new ItemsPage ( ) );
    }
  catch ( Exception ex )
    {
    DisplayAlert ( "Error", ex.Message, "ok" );
    throw ex;
    }
  }


What I have tried:

i am using this code for save the details first time its hitting correctly but second time i am getting Packet received out-of-order. Expected 1; got 2.' this Error can you please help me on this.. i tried but didn't get answer for this
Posted
Updated 9-May-21 10:47am
v2
Comments
gggustafson 25-Apr-21 15:18pm    
I do not like using "Object" as a variable. It can be confused with the System Object.

The parameter names in your AddWithValue statements are not those defined in your query. This makes your code difficult to understand. I suggest you name your parameter names the same as your DB column names.
Muthu vj 29-Apr-21 12:21pm    
thank you i got it

1 solution

I believe your @references need to line uyp between the insert statement and the cmdParameters. Change them to match.

"VALUES ( @Action, " +
"@Object, " +
"@Buyat, " +
"@TP1, " +
"@TP2, " +
"@SL, " +
"@isActive)";

Should be used as the references in the adding of the command parameters

cmd.Parameters.AddWithValue ( "@Action", deserialized.Action );
cmd.Parameters.AddWithValue ( "@Object", deserialized.Object );
cmd.Parameters.AddWithValue ( "@Buyat", deserialized.Buyat );
cmd.Parameters.AddWithValue ( "@TP1", deserialized.TP1 );
cmd.Parameters.AddWithValue ( "@TP2", deserialized.TP2 );
cmd.Parameters.AddWithValue ( "@SL", deserialized.SL );
cmd.Parameters.AddWithValue ( "@isActive", "true" );
 
Share this answer
 
Comments
CHill60 10-May-21 3:44am    
This is not the case with named parameters (but is the case if you are using something like Access where the parameters are marked with ?).
The problem was that the OP had differently named parameters - as pointed out by gggustafson

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