-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database acces display insert
91 lines (46 loc) · 1.42 KB
/
Database acces display insert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//Access Database
using System:
using System.Collections.Generic;
using System.Ling
using System. Web:
using System.Web.Ul;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient; using System.Data.OleDb;
public partial class database 2: System.Web.UI.Page
//display
protected void b1 Click(object sender, EventArgs e)
イ string str="Provider=Microsoft.ACE.OLEDB.12.0;Data
Source D:\\TYIT120\\mydb.accdb";
OleDbConnection con = new OleDbConnection(str);
try
//SqlConnection con-new SqlConnection();
OleDbCommand cmd=new OleDbCommand("select *
from emp",con);
con.Open();
GridView1.DataSource=cmd.ExecuteReader(); }
GridView1.DataBind();
catch(Exception ef)
Ibltext. Text ef.Message;
finally
}
)
con.Close(); )
//insert
protected void b2_Click(object sender, EventArgs e)
( string str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\TYIT120\\mydb.accdb";
string insstr;
//int i = 10;
insstr="insert into emp (ename,eaddr,eage,emob)
values(\""+tbname.Text+"\",\""+tbadd. Text+"\","+int.Parse(tbage.Text) +","+int.Parse(tbmob.Text)+")";
OleDbConnection con = new OleDbConnection(str);
Ibltext. Text insstr;
OleDbCommand cmd = new OleDbCommand(insstr, con);
int added = 0;
try
added = cmd.ExecuteNonQuery();
con.Open();
Ibitext.Text = added.ToString() + "Records inserted"; }
catch (Exception ef)
Ibltext.Text = "Error inserting records"+ef.Message; }
finally { con.Close(); }}}