






1
protected void btnUpLoad_Click(object sender, EventArgs e)
2
{ //若此处未加逻辑判断,如果excel文件不存在则程序将会报异常
3
if(System.IO.File.Exists(MapPath(DataBase)))
4
{
5
6
OleDbConnection OleCon = new OleDbConnection( ExcelStr+MapPath(DataBase));
7
OleDbDataAdapter OleDAp = new OleDbDataAdapter( "SELECT prgName,PlayTime,prgColumn FROM [Sheet1$] ", OleCon);
8
DataSet ds = new DataSet();
9
OleDAp.Fill(ds);
10
11
string prgName,playTime,prgColumn,sSQL;
12
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["SqlString"]);
13
conn.Open();
14
SqlCommand cmd;
15
try
16
{
17
18
foreach (DataRow dr in ds.Tables[0].Rows)
19
{
20
21
prgName = dr["prgName"].ToString();
22
playTime = dr["PlayTime"].ToString();
23
prgColumn = dr["prgColumn"].ToString();
24
25
sSQL = "Insert Into Ax_Program (prgName,PlayTime,prgColumn,prgComment) Values ('"+prgName +"','" + playTime+ "','"+prgColumn+"','"+DateTime.Now.ToString("yyyy-MM-dd HH:mm")+"Excel导入')";
26
cmd = new SqlCommand(sSQL,conn);
27
cmd.CommandType = CommandType.Text;
28
cmd.ExecuteNonQuery();
29
cmd.Dispose();
30
31
}
32
}
33
catch (Exception)
34
{
35
Response.Write("<script language='javascript'>window.alert('导入失败')</script>;");
36
return;
37
}
38
finally
39
{
40
41
conn.Close();
42
conn.Dispose();
43
}
44
Response.Write("<script language='javascript'>window.alert('导入成功')</script>;");
45
ExlDataGrid.Visible=false;
46
47
OpenAndBindNew();
48
49
lbWarning.Visible=false;
50
lbWarningS.Visible=true;
51
lbWarningS.Text="本此操作导入的节目信息";
52
}
53
else
54
{
55
Response.Write("<script language='javascript'>window.alert('Excel文件不存在!')</script>;");
56
}
57
}

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
