0
private void buttonSend_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 = "My API";

            connection.Open();

            command = new SqlCommand("Select  Column1 From Table1", connection);

            datareader = command.ExecuteReader();
           
            while (datareader.Read())
            {
                string Column = datareader["Column1"].ToString();
                parameter.Add("1", Column.ToString());//target numbers
                parameter.Add("2", TextBox.Text);//message
                parameter.Add("3", "Username");
                parameter.Add("passwd", "Password");

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

                functionReturnValue = (new System.Text.UTF8Encoding()).GetString(rpb);
            }

            datareader.Close();
            connection.Close();

            MessageBox.Show("Message is sent!.", "Message", MessageBoxButtons.OK);
        }
}

I'm working with a SqlDatareader to retrieve data from my column in my database which contains numbers where I want to send my textmessage from a textbox, the problem is that my datareader only reads the first content in the column where I contain my numbers and only sends a single message, instead of sending the messages from the textbox to all the numbers in Column1. Please help.

19
  • Try debugging by putting breakpoints and see what values you are getting from the database. Commented Feb 22, 2022 at 10:14
  • From : "Select Column1 From Table1" To : "Select * From Table1" Commented Feb 22, 2022 at 10:30
  • @jdweng i get an error when i include * System.Data.SqlClient.SqlException: 'Incorrect syntax near 'Column1'.', i only want to read column1 not all the columns in table1 Commented Feb 22, 2022 at 10:34
  • Why are you getting a period when I posted an asterisk? If you are only getting one value then there is only one value in the column and the other values are in other columns. Commented Feb 22, 2022 at 10:40
  • @jdweng i currently have 4 numbers in column1 its stops in the first value of column Commented Feb 22, 2022 at 10:59

0

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.