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.

4
  • 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 Commented Feb 18, 2022 at 12:01
  • Thank you very much, I appreciate your help. Commented Feb 18, 2022 at 12:51
  • @Charlieface, How Am i going to retrieve data what code do i use? and what is "using"\ Commented Feb 18, 2022 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 stackoverflow.com/questions/4018114/… Commented Feb 18, 2022 at 15:51

1 Answer 1

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());
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much sir, I've been stuck with this for a while. This is very helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.