<connectionStrings>
<add name="conn" connectionString="Integrated Security=SSPI;Database=lgzy;Server=localhost"/>
</connectionStrings>
xing13622429..
第一个例子:利用Girdview显示数据库表的内容
<connectionStrings>
<add name="conn" connectionString="Integrated Security=SSPI;Database=student;Server=localhost"/>
</connectionStrings><connectionStrings>
前台代码:
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
后台代码:
using System.Data.SqlClient;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
if (!Page.IsPostBack)
{
string connStr = ConfigurationManager.ConnectionStrings ["conn"].ConnectionString; //连接字符串
SqlConnection conn = new SqlConnection(connStr); //创建数据库连接
conn.Open(); //打开数据库
SqlDataAdapter ad = new SqlDataAdapter("Select*from studentinfo", conn); //使用sqldataAdapter对象定义ad
DataSet ds = new DataSet(); //填充dataset对象
ad.Fill(ds);
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
第二个进行分页和用repeater显示数据
第三个:连接数据库绑定dropdownlist
前台代码:
<asp:DropDownList ID="DropDownListNO" runat="server">
</asp:DropDownList>
using System.Data.SqlClient;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownListNO.Items.Clear();
string connStr = "Integrated Security=SSPI;Database=student;Server=localhost";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select 姓?名? from studentinfo";
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
DropDownListNO.Items.Add(new ListItem(dr["姓?名?"].ToString()));
}
}
}
};
4:注册页以及注入数据库代码
string constr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
string sql = "insert into studentinfo(姓?名?,密¨1码?,性?别àe,地ì?址?¤,爱??好?)values(@UserName,@UserPwd,@Sex,@address,@Rabbit)";
SqlParameter[] parameters =
{
new SqlParameter("@UserName",usename1.Text.Trim()),
new SqlParameter("@UserPwd",password1.Text.Trim()),
new SqlParameter("@Sex",sex),
new SqlParameter("@address",address1.Text.Trim()),
new SqlParameter("@Rabbit",introduce1.Text.Trim())
};//传参
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = sql;
cmd.Parameters.AddRange(parameters);
int rows = cmd.ExecuteNonQuery();
if (rows > 0)
{
Response.Write("注册成功");
}
else
{
Response.Write("注册失败");
}
con.Close();
五:小白留言板的登录后台
if (tname.Text == string.Empty || tpass.Text == string.Empty) //用户名和密码不能为空
{
Response.Write("<script>alert('用户名和密码不能为空')</script>");
}
else
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["getcon"].ConnectionString);//定义连接字符串
con.Open();
string cmdtext = "select u_name,u_pass from message_users where u_name=@name and u_pass=@pass"; //定义sql执行语句
SqlCommand com = new SqlCommand(cmdtext, con); //定义sqlcommand对象
com.Parameters.Add("@name", SqlDbType.VarChar).Value = ame.Text.ToString(); //利用Parameters来定义密码和用户
com.Parameters.Add("@pass", SqlDbType.VarChar).Value = this.tpass.Text.ToString();
SqlDataReader rs = com.ExecuteReader(); //利用command对象的Executeader方法
if (rs.Read())
{
Session["name"] = ame.Text;
rs.Close();
com.Clone();
Response.Redirect("showmessage.aspx");
}
else
{
Response.Write("<script>alert('用户名和密码错误')</script>");
}
}
}
}
2;表情的引用和使用:
<tr>
<td class="td" >
表情:</td>
<td class="td" >
<asp:RadioButtonList ID="dface" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" Width="88%"></asp:RadioButtonList></td>
</tr>
后台代码:
private void datalist()
{
for (int i = 0; i <= 19; i++)
{
this.dface.Items.Add("<img border=\"0\" src=\"image/"+i.ToString()+".gif\"/>"); //表情的链接相对路径
this.dface.Items[i].Value = i.ToString() + ".gif";
}
this.dface.Items[0].Selected = true; //定义第一个表情初始化选中
}
3;留言的后台注册页
protected void btnsend_Click(object sender, EventArgs e)
{
try
{
liuyan.insert(this.tsubject.Text, ame.Text, ail.Text, this.tqq.Text, this.tphone.Text, Request.UserHostAddress, this.tadd.Text, this.thttp.Text, this.dface.SelectedValue, nt.Text);
}
catch (Exception aa)
{
Response.Write(aa.Message);
}
Response.Redirect("showmessage.aspx");
}
4、获取页面传过来的值sClassId = Request["classid"].ToString();
<div id="tz_con" class="show">
<img src="images/9.jpg" />
<asp:Repeater ID="rpNews2" EnableViewState="false" runat="server">
<ItemTemplate>
<p>
<a href='detials.aspx?type=learnTask&Id=<%#Eval("Id") %>' target="_blank"><span>
<%#Eval("learn_title")%></span><%#IsRemind2(Eval("Id").ToString())%></a><span>
<%#Eval("learn_time")%></span></p>
</ItemTemplate>
</asp:Repeater>
</div>
<div id="xxrw" class="hide">
<img src="images/9.jpg" />
<asp:Repeater ID="rpNews" EnableViewState="false" runat="server">
<ItemTemplate>
<p>
<a href='detials.aspx?type=News&Id=<%#Eval("Id") %>' target="_blank"><span>
<%#Eval("n_time")%></span><%#Eval("n_title")%></a></p>
</ItemTemplate>
</asp:Repeater>
</div>
#tz_con,#xxrw {
width: 930px;
height: 188px;
background: #f5f5f5;
padding: 3px 5px;简单的mysql语句
}
#tz_con img,#xxrw img {
float: left;
}
#tz_con p,#xxrw p {
padding: 5px;
height: 17px;
}
#tz_con p a,#xxrw p a {
text-decoration: none;
color: #000;
padding: 0 0 0 15px;
margin: 0 0 0 10px;
background: url(../images/10.jpg) no-repeat 2px 1px;
font-size: 14px;
}
#tz_con p a:hover,#xxrw p a:hover {
color: #ee9134;
}
#tz_con p span,#xxrw p span {
float: right;
cursor: pointer;
}
1、导入学生那块少了一段代码。。。。。
2、三分屏学生界面总体不好,老师说最好重改。
3、用那个控件转化swf,本地好好的。到服务器上就出问题了,搞了那么久才搞定
4、美工的那块自己加了那么多东西,最后还是要美工
来做好美化!
5、用了三层和4.0来做,少波师兄说不要用这样来做。。。。。。
6、表的设计不够,后面让我不断往里加东西,不断补!!!!!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论