0
private void button1_Click(object sender, EventArgs e)
{
    object functionReturnValue = null;

    using (System.Net.WebClient client = new System.Net.WebClient())
    {
        System.Collections.Specialized.NameValueCollection parameter = new System.Collections.Specialized.NameValueCollection();
        string url = "https://www.itexmo.com/php_api/api.php";

        conn.Open();
        cmd = new SqlCommand("select  FirstYear from Numbers", conn);

        dr = cmd.ExecuteReader();
           
        parameter.Add("1", "09123456789");
        parameter.Add("2", richTextBox1.Text);
        parameter.Add("3", "TR-CCDIS629375_B9R26");
        parameter.Add("passwd", "u$454g4gi&w&");

        dynamic rpb = client.UploadValues(url, "POST", parameter);

        functionReturnValue = (new System.Text.UTF8Encoding()).GetString(rpb);
        MessageBox.Show("Message has been sent!.", "Message", MessageBoxButtons.OK);
        dr.Close();
        conn.Close();
    }
}

This code here is a normal code to send sms using an API to a single number, I only added the SqlCommand to it and I know what to do about it, how am I going to get the multiple numbers from my database which I want to access using a comboBox? As you can see in my cmd SqlCommand I'm trying to retrieve the data but I don't know to how to convert into a parameter to replace the single number in the parameter and send sms to multiple numbers. I am new to C#, any help is much appreciated.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • You need to loop the reader with `while (dr.Read())` and then retrieve the values using `dr["FirstYear"]`. You also need to dispose your connection, command and reader with `using` – Charlieface Feb 18 '22 at 12:01
  • Thank you very much, I appreciate your help. – kenluffy32 Feb 18 '22 at 12:51
  • @Charlieface, How Am i going to retrieve data what code do i use? and what is "using"\ – kenluffy32 Feb 18 '22 at 14:47
  • Like you have ealier `using (var cmd = new SqlCommand(...`. I suggest you read up on ADO.Net datareaders, try here for starters https://stackoverflow.com/questions/4018114/read-data-from-sqldatareader – Charlieface Feb 18 '22 at 15:51

1 Answers1

0

how am i going to get the multiple numbers from my database which i want to access using a comboBox?

You could do this in e.g. the constructor of the form after InitializeComponent(), or some other button that is a "load numbers from db" button:

var dt = new DataTable();
using var da = new SqlDataAdapter("select  FirstYear from Numbers", conn); //perhaps use the overload that takes a connectionstring instead; avoid having SqlConnections in class level variables
da.Fill(dt);
_numbersComboBox.DisplayMember = "FirstYear";
_numbersComboBox.ValueMember = "FirstYear";
_numbersComboBox.DataSource = dt;

Then in your SMS send routine:

parameter.Add("2", _numbersComboBox.SelectedValue.ToString());
Caius Jard
  • 72,509
  • 5
  • 49
  • 80