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);
}
1
  • You should use ExecuteScalar(); instead of ExecuteNonQuery(); And also, you code seems to missing to execute emailf SqlCommand. Commented Jul 27, 2017 at 10:23

1 Answer 1

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

8 Comments

Thank you so much Balagurunathan Marimuthu it works. Thank you very much for your help.
@vicserna1997 Glad it helped. please mark this answer as helpful and if you can up vote as well. :)
I will :) I also have another problem
@vicserna1997 Please post that as another question and Comment your new question over here. I will try to answer it.
Thank you but I have to wait 90 minutes for another question Balagurunathan Marimuthu
|

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.