Back to Browse

Login with Postgresql using VS2010 C#

33.8K views
Aug 16, 2011
7:07

part1 Login with Postgresql using VS2010 C# using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Npgsql; namespace WindowsFormsApplication4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnCancel_Click(object sender, EventArgs e) { Application.Exit(); } private void btnLogin_Click(object sender, EventArgs e) { bool blnfound = false; NpgsqlConnection conn = new NpgsqlConnection("Server=localhost;Port=5432; User Id=postgres;Password=jimmy;Database=test"); conn.Open(); // opens the connection NpgsqlCommand cmd = new NpgsqlCommand("select * from login where name = '" + tb1.Text + "' and password='" + tb2.Text + "'", conn); NpgsqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { blnfound = true; Form2 f5 = new Form2(); f5.Show(); this.Hide(); } if (blnfound == false) MessageBox.Show("Name or Password is not correct !!:)", " Awan Malik's Message Box ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); dr.Close(); conn.Close(); } } } I will soon post the code for VB.net.

Download

0 formats

No download links available.

Login with Postgresql using VS2010 C# | NatokHD