The following procedure shows how to create a login form in Visual Studio and connect with Microsoft Access Database 2010 in 10 steps.
Step 1
Open any version of Visual Studio you have installed in your machine; I have Visual Studio 12. When open, it will look like this:
Step 1
Open any version of Visual Studio you have installed in your machine; I have Visual Studio 12. When open, it will look like this:
In Installed Templates the first option is Visual C# language and then select Windows Forms application.
In the following see the Name label and already show the default name WindowFormsApplication1.
You can change the name as you wish or as per program creation you can mention and click and OK.
Step 4
After clicking OK a simple Windows Forms form will look like:
Step 5
In your Windows Forms form set the size as needed. You can set the size and if you want to set the size by properties then right-click on the Windows Forms form and in the last option of show properties click to see the Windows Forms form properties.
In your Windows Forms form set the size as needed. You can set the size and if you want to set the size by properties then right-click on the Windows Forms form and in the last option of show properties click to see the Windows Forms form properties.
Click the Toolbox and drag and drop you need Windows Controls
Click the Toolbox and drag and drop you need Windows Controls
Step 6
Watch Video How Set All Controls in Form
Watch Video How Set All Controls in Form
Step 7
Now drag all text boxes and labels and buttons and arrange
all the tools.
Now the final design looks like this type.
Now the final design looks like this type.
Step 8
Now Create Microsoft Access 2010 Database and Create One Table “login_tbl”.
Step 9
set Two Fields in Table “F_Username” and “F_Password”
Step 10
Create Database Path “Connectionstring”
Create Database Path “Connectionstring”
Now Programming Start for Connectivity Between C# Windows Form and Microsoft Access Database.
Source Code Are as Below.
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.OleDb;
namespace Login_Sample_1
{
public partial class Form1 : Form
{
OleDbConnection con;
OleDbCommand cmd = new OleDbCommand();
string sconnections = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source="
+ Application.StartupPath + "\\db.ACCDB;Persist
Security Info=False";
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
string str="select F_Username from Login_tbl where F_Username='"+txtuser .Text +"' and
F_Password='"+txtpaass
.Text +"'";
con = new OleDbConnection(sconnections);
cmd.Connection = con;
con.Open();
cmd.CommandText = str;
OleDbDataReader dr = cmd.ExecuteReader();
if
(dr.Read() == true)
{
MessageBox.Show("Login Successfully");
MessageBox.Show(dr[0].ToString());
}
else
{
MessageBox.Show("Username password wrong");
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
2 Comments
sir please upload video on how to connect oracle 10g express edition_2 to C# project....plz..plz..plz...sir
ReplyDeleteOk i will do it as soon as possible
Delete