ASP.NET连接sql2008数据库
原创
©著作权归作者所有:来自51CTO博客作者x954818696的原创作品,请联系作者获取转载授权,否则将追究法律责任
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Web;
5: using System.Web.UI;
6: using System.Web.UI.WebControls;
7:
8: using System.Data.SqlClient;
9: using System.Data;
10: using System.Configuration;
11:
12: public partial class _Default : System.Web.UI.Page
13: {
14: protected void Page_Load(object sender, EventArgs e)
15: {
16: // 连接sql数据库
17: String sqlconn = "Data Source=SEEBRO-PC\\SQLEXPRESS;Initial Catalog=SuperMarket;Integrated Security=True";
18: SqlConnection myConnection = new SqlConnection(sqlconn);
19: myConnection.Open();
20:
21: //定义SqlCommand类
22: SqlCommand myCommand = new SqlCommand();
23: myCommand.Connection = myConnection;
24: myCommand.CommandType = CommandType.StoredProcedure;
25: myCommand.CommandText = "bytype";
26: //存储过程传参
27: SqlParameter parInput = myCommand.Parameters.Add("@type", SqlDbType.SmallMoney);
28: parInput.Direction = ParameterDirection.Input;
29: parInput.Value = 2;
30:
31: SqlDataReader myReader = myCommand.ExecuteReader();
32:
33: Response.Write("<table border=1 cellspaceing=0 cellpadding=2>");
34: Response.Write("<tr bgcolor=#DAB4B>");
35: for (int i = 0; i < myReader.FieldCount; i++)
36: Response.Write("<td>" + myReader.GetName(i) + "</td>");
37: Response.Write("</tr>");
38:
39: while (myReader.Read())
40: {
41: Response.Write("<tr>");
42: for (int i = 0; i < myReader.FieldCount; i++)
43: Response.Write("<td>" + myReader[i].ToString() + "</td>");
44: Response.Write("</tr>");
45: }
46: Response.Write("</table>");
47:
48: myReader.Close();
49: myConnection.Close();
50: }
51: }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }上一篇:begin
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
asp.net网页选择身份进行登录的简单代码,asp连接数据库,使用asp:Panel、asp:DropDownList控件
asp.net
asp.net 数据库 后端 System Web -
asp.net连接SQL数据库做登录
由于项目的需
asp.net 数据库 sql object javascript -
java对登录数据包进行完整性校验 java数据库实现登录
1,第一步准备JDBC对应数据库的jar包我这里准备的是mysql的环境这是mysql对应的jar包:https://downloads.mysql.com/archives/c-j/下载完成后解压 把jar包引入到项目当中去这以idea教育版为例 打
java对登录数据包进行完整性校验 1024程序员节 java jar 数据库