Csharp connect to SQL Server

Published: 06 July 2023
on channel: HUY HOÀNG
613
0

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

namespace Salutations
{
public partial class Form1 : Form
{
private const string connect = "Data Source=MSI\\SQLEXPRESS;Initial Catalog=Howdy;Integrated Security=True";
public Form1()
{
InitializeComponent();
}

private void btnLogin_Click(object sender, EventArgs e)
{
string name = txtUser.Text;
string pass = txtPass.Text;

try
{
using (SqlConnection conn = new SqlConnection(connect))
{
conn.Open();
string sql = "SELECT * FROM hithere WHERE userName = @name AND passWord = @pass ";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@pass", pass);

SqlDataReader render = cmd.ExecuteReader();
if (render.HasRows)
{
MessageBox.Show("lOGIN SUSSECCFUL");
}
else
{
MessageBox.Show("LOGIN FAILSE");
}
}
}catch(Exception ex)
{
MessageBox.Show("Connect failse", ex.Message);
}
}

private void btnExit_Click(object sender, EventArgs e)
{
DialogResult thongbao;
thongbao = (MessageBox.Show("Do you want exit? ", "thongbao", MessageBoxButtons.YesNo, MessageBoxIcon.Warning));
if(thongbao == DialogResult.Yes)
{
Application.Exit();
}
}
}
}


On this page of the site you can watch the video online Csharp connect to SQL Server with a duration of hours minute second in good quality, which was uploaded by the user HUY HOÀNG 06 July 2023, share the link with friends and acquaintances, this video has already been watched 613 times on youtube and it was liked by 0 viewers. Enjoy your viewing!