how to create a web page form in c with two buttons login an

how to create a web page form in c# with two buttons login and Contact and link it with my database.

Solution

Visual basic and C# is used together to build web applications. Use Visual Studio IDE create a anew project choose ASP.NeT web application.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;
using SqlDataReader;

namespace RegdForms
{
    public partial class Form1 : Form
    {
      SqlConnection con = new SqlConnection(@\"Data Source=USER;Initial Catalog=admin;Integrated Security=True\"); // making connection
       public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            button1.Text = \"login\";
            button2.Text= \"contact\";
        }

        private void button1_Click(object sender, EventArgs e)
           {
         
       SqlDataAdapter sda = new SqlDataAdapter(\"SELECT COUNT(*) FROM login WHERE username=\'\"+ textBox1.Text +\"\' AND password=\'\"+ textBox2.Text +\"\'\",con);
            /* in above line the program is selecting the whole data from table and the matching it with the user name and password provided by user. */
       DataTable dt = new DataTable(); //this is creating a virtual table
       sda.Fill(dt);
       if (dt.Rows[0][0].ToString() == \"1\")
       {
       this.Hide();
      new home().Show();
       }
       else
       MessageBox.Show(\"Invalid username or password\");
     
        }
    }
   private void button2_Click(object sender, EventArgs e){
       con= new SqlConnection();
       con.open();
       SqlCommand command = new SqlCommand(\"SELECT * FROM TableName login FirstColumn = @0\", conn);
       command.Parameters.Add(new SqlParameter(\"0\", 1));
        SqlDataReader reader = command.ExecuteReader();
               {
                    Console.WriteLine(\"FirstColumn\\tSecond Column\\t\\tThird Column\\t\\tForth Column\\t\");
                    while (reader.Read())
                    {
                        Console.WriteLine(String.Format(\"{0} \\t | {1} \\t | {2} \\t | {3}\",
                            reader[0], reader[1], reader[2], reader[3]));
                    }
                }
                Console.WriteLine(\"contact info displayed\");
  
  
   }
}

how to create a web page form in c# with two buttons login and Contact and link it with my database.SolutionVisual basic and C# is used together to build web ap
how to create a web page form in c# with two buttons login and Contact and link it with my database.SolutionVisual basic and C# is used together to build web ap

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site