Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Assignment 2 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

//Code For Signing In Page

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Assignment2
{
public partial class Form1 : Form
{
//Initializing SQL connection

SqlConnection con = new SqlConnection();


SqlCommand com = new SqlCommand();

public Form1()
{
InitializeComponent();
// The link to our local MSSQL Database
con.ConnectionString = @"Data Source = (localdb)\MSSQLLocalDB; Initial Catalog =
master; Integrated Security = True";

private void button1_Click(object sender, EventArgs e)


{

con.Open();
com.Connection = con;
com.CommandText = "SELECT * FROM Users";

SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
//Checking If Credentials Provided by user are correct and display necessary
message

if (textBox1.Text.Equals(dr["usename"].ToString())&&
textBox2.Text.Equals(dr["password"].ToString()))
{

string username = dr["usename"].ToString();


MessageBox.Show("Welcome Back " + username, "Successful",
MessageBoxButtons.OK, MessageBoxIcon.Information);

}
else
{
string username = dr["usename"].ToString();
MessageBox.Show(username + "Cant Login", "Error ", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}

con.Close();

}
}
}

//Code For Loading Data on The Gridview

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Assignment2
{
public partial class Projects : Form
{
// The link to our local MSSQL Database
string connectionString = @"Data Source = (localdb)\MSSQLLocalDB; Initial Catalog =
master; Integrated Security = True";
public Projects()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
sqlCon.Open();
//Assuming the name of the table in the database is PROJECTS

SqlDataAdapter sqlDa = new SqlDataAdapter("SELECT *FROM PROJECTS ", sqlCon);


DataTable dataTable = new DataTable();
sqlDa.Fill(dataTable);

//Direct Method of loading data from table in databse to a gridview


dataGridView1.AutoGenerateColumns = dataTable;

sqlCon.Close();
}
}
}
}

You might also like