0

My output on SQL query is not viewing on my textbox, when the form load it must be automatically inserted to my textbox. The only output on my textbox is System.Data.SqlClient.SqlCommand

I don't know whats wrong or missing on my codes. Please help me, sorry I'm just a newbie on c#

Any type of response is greatly appreciated. Thank you in advance.

private void EmailGen_Load(object sender, EventArgs e)
{
    connect.Open();
    string emailto = "select emailaddress from emails where password = ''";
    string emailfr = "select emailaddress from emails where password != null";
    SqlCommand emailt = new SqlCommand(emailto, connect);
    SqlCommand emailf = new SqlCommand(emailfr, connect);
    emailt.ExecuteNonQuery();

    txBEmailRec.Text = emailt.ToString();
    txBEmailFr.Text = emailf.ToString(); ;
    connect.Close();

    // TODO: This line of code loads data into the 'kwemDataSet.tblProducts' table. You can move, or remove it, as needed.
    this.tblProductsTableAdapter.Fill(this.kwemDataSet.tblProducts);
}
Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44
vicserna1997
  • 97
  • 1
  • 7

1 Answers1

1

You should use ExecuteScalar(); instead of ExecuteNonQuery(); And also, you code seems to missing to execute emailf SqlCommand.

You could see this reference as well.

private void EmailGen_Load(object sender, EventArgs e)
{
    connect.Open();
    string emailto = "select emailaddress from emails where password = ''";
    string emailfr = "select emailaddress from emails where password != null";
    SqlCommand emailt = new SqlCommand(emailto, connect);
    SqlCommand emailf = new SqlCommand(emailfr, connect);

    txBEmailRec.Text = emailt.ExecuteScalar().ToString();
    txBEmailFr.Text = emailf.ExecuteScalar().ToString();
    connect.Close();

    // TODO: This line of code loads data into the 'kwemDataSet.tblProducts' table. You can move, or remove it, as needed.
    this.tblProductsTableAdapter.Fill(this.kwemDataSet.tblProducts);
}
Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44