在B页面总select语句这样来写:
string strSQL="select * from yourtable where 关键字段="+Session["UserName"].ToString();
剩下的就是来绑定数据库到DataGrid中了,我想绑定的工作你会实现了吧.
顺便附上例子:
C#的,你在翻译一下吧:protected System.Data.SqlClient.SqlConnection cn;
protected System.Data.SqlClient.SqlDataAdapter da;
protected System.Data.DataSet ds;
private void getbindDataGrid()
{
cn= new SqlConnection(ConfigurationSettings.AppSettings["ds"]);//连接数据库操作
string strSQL="select * from yourtable where 关键字段="+Session["UserName"].ToString();
da = new SqlDataAdapter(strSQL,cn);
ds = new DataSet();
cn.Open();
da.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
cn.Close();
}
string strSQL="select * from yourtable where 关键字段="+Session["UserName"].ToString();
剩下的就是来绑定数据库到DataGrid中了,我想绑定的工作你会实现了吧.
顺便附上例子:
C#的,你在翻译一下吧:protected System.Data.SqlClient.SqlConnection cn;
protected System.Data.SqlClient.SqlDataAdapter da;
protected System.Data.DataSet ds;
private void getbindDataGrid()
{
cn= new SqlConnection(ConfigurationSettings.AppSettings["ds"]);//连接数据库操作
string strSQL="select * from yourtable where 关键字段="+Session["UserName"].ToString();
da = new SqlDataAdapter(strSQL,cn);
ds = new DataSet();
cn.Open();
da.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
cn.Close();
}
谢谢您的帮助,我将您提供的代码修改如下,但提示如下信息:
类型“String”的值无法转换为“System.Data.OleDb.OleDbCommand”。
请问如何修改啊,再次打扰,实在不好意思!代码如下: Sub Page_Load(sender As Object, e As EventArgs)
'记录用户名,并显示
if not (Session("用户名") is nothing) then
Label1.Text = "<b>欢迎" & Session("用户名") & "登录!</b>"
else
label1.text="欢迎~~~~欢迎!"
end if
dim ds as dataset=new dataset
dim conn as oledbconnection
conn=new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&server.mappath("/qkglxt/data/data.mdb"))
dim mycommand as oledbDataAdapter
mycommand=new oledbDataAdapter("select * from tbledit where edit="+Session("用户名").ToString())
conn.open()
mycommand.fill(ds)
grdmain.datasource=new dataview(ds.tables(0))
grdmain.databind()
end sub
-------------------------
这句应该这样来写吧
mycommand=new oledbDataAdapter("select * from tbledit where edit="+Session("用户名").ToString(),conn);
Session("用户名")
的值给变量,在写dim str as string=Session("用户名")mycommand=new oledbDataAdapter("select * from tbledit where edit=" & str &,conn)
是不是得加二个'呀!
应该是mycommand=new oledbDataAdapter("select * from tbledit where edit='" & str &"'",conn)
你用的"+Session("用户名")还是C#的语法,不能识别的。