Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieving data from SQL server 2008r2 using winforms
    primarykey
    data
    text
    <p>I am creating a c# windows form app, which will retrieve the data from a DB that is already created in sql server2008r2. There are 2 win forms in my app, 1st one is for getting the login details, the 2nd one is for display the data that are relevant to given UserID &amp; Password. I can't get the data to my 2nd form. This is my code:</p> <p><em><strong></em>**<em>*</em>****</strong><em>1st form</em><strong><em>*</em>**<em>*</em></strong></p> <pre><code> public partial class FormLog_in : Form { SqlConnection con = new SqlConnection("Data source=CHINTHAK-PC ; Initial Catalog=FlintecTest; Integrated Security = yes;"); SqlDataAdapter da = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand(); public FormLog_in() { InitializeComponent(); } private void btnLogIn_Click(object sender, EventArgs e) { if (!(string.IsNullOrEmpty(txtUserName.Text)) &amp;&amp; !(string.IsNullOrEmpty(txtPassword.Text))) { con.Open(); string query = "SELECT count(*) FROM LogIn WHERE UesrName=@1 AND PassWord=@2 "; cmd = new SqlCommand(query, con); cmd.Parameters.Add("@1", SqlDbType.NVarChar).Value = txtUserName.Text; cmd.Parameters.Add("@2", SqlDbType.NVarChar).Value = txtPassword.Text; int count = Convert.ToInt32(cmd.ExecuteScalar()); con.Close(); if (count &gt; 0) { MessageBox.Show("Valid Username and Password"); Welcome f1 = new Welcome(); f1.Show(); } else MessageBox.Show("Invalid Username or Password try again"); } </code></pre> <p><strong><em>*</em>****</strong><em>2nd form</em><strong><em>*</em>*</strong></p> <pre><code>public partial class Welcome : Form { string query = null; SqlConnection con = new SqlConnection("Data source=CHINTHAK-PC ; Initial Catalog=FlintecTest; Integrated Security = yes;"); SqlDataAdapter da = new SqlDataAdapter(); BindingSource userTable = new BindingSource(); DataSet ds = new DataSet(); public Welcome() { InitializeComponent(); } private void Welcome_Load(object sender, EventArgs e) { query = "SELECT * FROM Users WHERE UserName=@x AND Users.Password=@y ";//x should be given username by current login da.SelectCommand = new SqlCommand(query, con); //y should be given password by current login ds.Clear(); da.Fill(ds, "usr"); userTable.DataSource = ds.Tables["usr"]; txtFristName.DataBindings.Add(new Binding("Text", userTable, "FirstName")); txtLastName.DataBindings.Add(new Binding("Text", userTable, "LastName")); txtAddress.DataBindings.Add(new Binding("Text", userTable, "Address")); txtTelephone.DataBindings.Add(new Binding("Text", userTable, "Telephone")); txtEmail.DataBindings.Add(new Binding("Text", userTable, "Email")); txtFax.DataBindings.Add(new Binding("Text", userTable, "Fax")); txtSection.DataBindings.Add(new Binding("Text", userTable, "Section")); txtPosition.DataBindings.Add(new Binding("Text", userTable, "Position")); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload