How to display the data from the form 1 into the form 2












0















I want to select 3 columns from the database on 'form 1' which is firstname, username and rolename to display it on form 2.
The firstname and username are display on the form 2, but the rolename is not appear, is there error on my code?
The error in the picture in form 2 at part rolename suppose to be display "lab user on liquid"/"lab user on raw food".



form1 and form 2



FORM 1



 namespace labuser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.\sqlexpress;Initial Catalog=AlcoholSystem;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("select firstname,rolename from tblUser where username='" + username.Text + "' and password = '" + password.Text + "'", con);
DataTable dt = new DataTable();
sda.Fill(dt);


if (dt.Rows.Count == 1)
{
MessageBox.Show("Username and password is correct.");
this.Hide();
Form2 ss = new Form2(username.Text, dt.Rows[0][0].ToString());
ss.Show();
}
else
{
MessageBox.Show("Please check your username and password!");
}
}


FORM 2



namespace labuser
{
public partial class Form2 : Form
{
SqlConnection con = new SqlConnection("Data Source=.\sqlexpress;Initial Catalog=AlcoholSystem;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
DataTable table = new DataTable();


string ports = SerialPort.GetPortNames();

public Form2(String Username, String firstname, String rolename)
{

InitializeComponent();
label5.Text = Username;
label8.Text = firstname;
label13.Text = rolename;


serialPort1.BaudRate = 9600;
}









share|improve this question



























    0















    I want to select 3 columns from the database on 'form 1' which is firstname, username and rolename to display it on form 2.
    The firstname and username are display on the form 2, but the rolename is not appear, is there error on my code?
    The error in the picture in form 2 at part rolename suppose to be display "lab user on liquid"/"lab user on raw food".



    form1 and form 2



    FORM 1



     namespace labuser
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    SqlConnection con = new SqlConnection("Data Source=.\sqlexpress;Initial Catalog=AlcoholSystem;Integrated Security=True");
    SqlDataAdapter sda = new SqlDataAdapter("select firstname,rolename from tblUser where username='" + username.Text + "' and password = '" + password.Text + "'", con);
    DataTable dt = new DataTable();
    sda.Fill(dt);


    if (dt.Rows.Count == 1)
    {
    MessageBox.Show("Username and password is correct.");
    this.Hide();
    Form2 ss = new Form2(username.Text, dt.Rows[0][0].ToString());
    ss.Show();
    }
    else
    {
    MessageBox.Show("Please check your username and password!");
    }
    }


    FORM 2



    namespace labuser
    {
    public partial class Form2 : Form
    {
    SqlConnection con = new SqlConnection("Data Source=.\sqlexpress;Initial Catalog=AlcoholSystem;Integrated Security=True");
    SqlCommand cmd = new SqlCommand();
    DataTable table = new DataTable();


    string ports = SerialPort.GetPortNames();

    public Form2(String Username, String firstname, String rolename)
    {

    InitializeComponent();
    label5.Text = Username;
    label8.Text = firstname;
    label13.Text = rolename;


    serialPort1.BaudRate = 9600;
    }









    share|improve this question

























      0












      0








      0








      I want to select 3 columns from the database on 'form 1' which is firstname, username and rolename to display it on form 2.
      The firstname and username are display on the form 2, but the rolename is not appear, is there error on my code?
      The error in the picture in form 2 at part rolename suppose to be display "lab user on liquid"/"lab user on raw food".



      form1 and form 2



      FORM 1



       namespace labuser
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      }

      private void button1_Click(object sender, EventArgs e)
      {
      SqlConnection con = new SqlConnection("Data Source=.\sqlexpress;Initial Catalog=AlcoholSystem;Integrated Security=True");
      SqlDataAdapter sda = new SqlDataAdapter("select firstname,rolename from tblUser where username='" + username.Text + "' and password = '" + password.Text + "'", con);
      DataTable dt = new DataTable();
      sda.Fill(dt);


      if (dt.Rows.Count == 1)
      {
      MessageBox.Show("Username and password is correct.");
      this.Hide();
      Form2 ss = new Form2(username.Text, dt.Rows[0][0].ToString());
      ss.Show();
      }
      else
      {
      MessageBox.Show("Please check your username and password!");
      }
      }


      FORM 2



      namespace labuser
      {
      public partial class Form2 : Form
      {
      SqlConnection con = new SqlConnection("Data Source=.\sqlexpress;Initial Catalog=AlcoholSystem;Integrated Security=True");
      SqlCommand cmd = new SqlCommand();
      DataTable table = new DataTable();


      string ports = SerialPort.GetPortNames();

      public Form2(String Username, String firstname, String rolename)
      {

      InitializeComponent();
      label5.Text = Username;
      label8.Text = firstname;
      label13.Text = rolename;


      serialPort1.BaudRate = 9600;
      }









      share|improve this question














      I want to select 3 columns from the database on 'form 1' which is firstname, username and rolename to display it on form 2.
      The firstname and username are display on the form 2, but the rolename is not appear, is there error on my code?
      The error in the picture in form 2 at part rolename suppose to be display "lab user on liquid"/"lab user on raw food".



      form1 and form 2



      FORM 1



       namespace labuser
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      }

      private void button1_Click(object sender, EventArgs e)
      {
      SqlConnection con = new SqlConnection("Data Source=.\sqlexpress;Initial Catalog=AlcoholSystem;Integrated Security=True");
      SqlDataAdapter sda = new SqlDataAdapter("select firstname,rolename from tblUser where username='" + username.Text + "' and password = '" + password.Text + "'", con);
      DataTable dt = new DataTable();
      sda.Fill(dt);


      if (dt.Rows.Count == 1)
      {
      MessageBox.Show("Username and password is correct.");
      this.Hide();
      Form2 ss = new Form2(username.Text, dt.Rows[0][0].ToString());
      ss.Show();
      }
      else
      {
      MessageBox.Show("Please check your username and password!");
      }
      }


      FORM 2



      namespace labuser
      {
      public partial class Form2 : Form
      {
      SqlConnection con = new SqlConnection("Data Source=.\sqlexpress;Initial Catalog=AlcoholSystem;Integrated Security=True");
      SqlCommand cmd = new SqlCommand();
      DataTable table = new DataTable();


      string ports = SerialPort.GetPortNames();

      public Form2(String Username, String firstname, String rolename)
      {

      InitializeComponent();
      label5.Text = Username;
      label8.Text = firstname;
      label13.Text = rolename;


      serialPort1.BaudRate = 9600;
      }






      c# sql-server database visual-studio






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 28 '18 at 17:33









      Nurul AsyiqinNurul Asyiqin

      174




      174
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Pass rolename as third param as



          Form2 ss = new Form2(username.Text, dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString());





          share|improve this answer


























          • Thanks a lot.! Its work! Thank you againnnnn...

            – Nurul Asyiqin
            Dec 28 '18 at 17:53











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962231%2fhow-to-display-the-data-from-the-form-1-into-the-form-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Pass rolename as third param as



          Form2 ss = new Form2(username.Text, dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString());





          share|improve this answer


























          • Thanks a lot.! Its work! Thank you againnnnn...

            – Nurul Asyiqin
            Dec 28 '18 at 17:53
















          0














          Pass rolename as third param as



          Form2 ss = new Form2(username.Text, dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString());





          share|improve this answer


























          • Thanks a lot.! Its work! Thank you againnnnn...

            – Nurul Asyiqin
            Dec 28 '18 at 17:53














          0












          0








          0







          Pass rolename as third param as



          Form2 ss = new Form2(username.Text, dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString());





          share|improve this answer















          Pass rolename as third param as



          Form2 ss = new Form2(username.Text, dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString());






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 28 '18 at 17:56









          Larnu

          16.4k41630




          16.4k41630










          answered Dec 28 '18 at 17:39









          SandeepSandeep

          5817




          5817













          • Thanks a lot.! Its work! Thank you againnnnn...

            – Nurul Asyiqin
            Dec 28 '18 at 17:53



















          • Thanks a lot.! Its work! Thank you againnnnn...

            – Nurul Asyiqin
            Dec 28 '18 at 17:53

















          Thanks a lot.! Its work! Thank you againnnnn...

          – Nurul Asyiqin
          Dec 28 '18 at 17:53





          Thanks a lot.! Its work! Thank you againnnnn...

          – Nurul Asyiqin
          Dec 28 '18 at 17:53


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962231%2fhow-to-display-the-data-from-the-form-1-into-the-form-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Mossoró

          Error while reading .h5 file using the rhdf5 package in R

          Pushsharp Apns notification error: 'InvalidToken'