6. Select your Project -> Add -> New Item ->
Data -> Service-Based Database
Give Database Name and press ok
Now open Server Explorer(ctrl+alt+s or View-Server Explorer)
Goto Data Connection -> your Database here->Add New table
Now Your Table is created(Screenshot :: next slide)
7.
8.
9.
10. using System;
using System.Data;
using System.Data.SqlClient;
namespace ADO_Example
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string name = textBox1.Text;
string password = textBox2.Text;
//we provide connection string
11. SqlConnection conn = new SqlConnection(@"Data
Source=(LocalDB)MSSQLLocalDB;AttachDbFilename='E:milanASP.netADO ExampleADO
ExampleStudentData.mdf';Integrated Security=True");
SqlCommand cmd = new SqlCommand();
conn.Open();
cmd.Connection = conn;
cmd.CommandText = "insert into Student(Name,Password)
values('"+name+"','"+password+"')";
int i = cmd.ExecuteNonQuery();//it's return affected row so it's give 1
if (i > 0)
{
MessageBox.Show("Data Inserted");
}
else
{
MessageBox.Show("Not Inserted");
}
}
}
}
12. Select Your Database -> Right Click ->Goto
Property
And You Get Connection String for your
Database