将数据存储在数据库中在网页上检索 [英] store data in data base & retrive on web page

查看:96
本文介绍了将数据存储在数据库中在网页上检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我想将数据存储到数据库中并将此数据显示在我的网页上.首先,我将数据存储到数据库(Sql Server 2005)中,但是在检索网页上的数据时遇到了一些问题.你能帮我吗?


谢谢.

Sir I want to stored data into database and show this Data on my web page. Firstly I am stored data into database (Sql Server 2005)which i done.But I have some problem to retrieving data on webpage. Can u help me.


Thanks.

推荐答案

您可以从一些有关数据库访问的教程开始 [^ ].
You could start with some tutorials on DB access here[^].


无效BindGridView()
{SqlConnection con =新的SqlConnection("server = WASIF \\ SQLEXPRESS; database = HRMS; integrated security = true");

SqlCommand cmd =新的SqlCommand("select * from abc",con);
con.Open();
SqlDataReader dtr = cmd.ExecuteReader();
如果(dtr.Read())
{
GridView1.DataSource = dtr;
GridView1.DataBind();
dtr.Close();
con.Close();
}
}
在页面加载事件中,将此函数称为
如果(!IsPostBack)
{
BindGridView();
}
void BindGridView()
{ SqlConnection con = new SqlConnection("server=WASIF\\SQLEXPRESS;database=HRMS;integrated security=true");

SqlCommand cmd = new SqlCommand("select * from abc", con);
con.Open();
SqlDataReader dtr = cmd.ExecuteReader();
if (dtr.Read())
{
GridView1.DataSource = dtr;
GridView1.DataBind();
dtr.Close();
con.Close();
}
}
On page Load Event call this function as
if (!IsPostBack)
{
BindGridView();
}


这篇关于将数据存储在数据库中在网页上检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆