Click here to Skip to main content
15,917,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a table communication ,i select days from communication & pass int days
this line how to write correct format in c#.
int days = int.Parse ("select del_nok_data_days from communication");

plz help some one.
thanks for advance

What I have tried:

public void getdata()
          {
           try
            {
               int days = int.Parse ("select del_nok_data_days from communication");
            string query = "Insert into store_pending_data (Primary_Barcode , Date_ , Time_ , STN_1Stat, STN_2Stat, STN_3Stat, STN_4Stat, STN_5Stat, STN_6Stat, STN_7Stat, STN_8Stat, STN_9Stat)" +
                   "(SELECT * FROM auto_status_4  where date(Date_) < DATE_SUB(NOW(),INTERVAL " + days + " DAY));";
               
              MySqlCommand cmd4 = new MySqlCommand(query, con);
              con.Open();
              cmd4.ExecuteNonQuery();
              con.Close();
         }
            catch (Exception ex)
            {
                LogFileWrite("getdata,frmAuto : " + ex.Message);
            }
        }
Posted
Updated 16-Mar-21 23:32pm
v2

1 solution

To answer your subject line first, since it isn;t related to teh question body:

Use TryParse[^] or TryParseExact[^]:

The code in your body will not work: typing an SQL command string and expecting that to automatically know which connection it should use, connect to the server, execute a command, pick a single result from the long list of returned values, and then change that to an integer is just wishful thinking - it just isn't going to happen.

Instead, you need to look at your DB and work out exactly what is in it, and what you want to return - because I can't honestly see anything in that code which looks like it was planned instead of thrown together. None of it will work; all of it will need thinking about.

Sorry if that sounds brutal - it does, but it's meant kindly - but guessing and hoping are not a viable design method: you need to think about your data and what you want to get out of it very carefully before you even start to code. I can't even work out from that what you are trying to do, much less help you fix it!
 
Share this answer
 

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