日期:2014-05-19  浏览次数:21085 次

databind()绑定数据时总是报错
<%@   Page   Language= "C# "   Debug= "true "   %>
<%@   Import   NameSpace= "System "%>
<%@   Import   NameSpace= "System.IO "%>
<%@   Import   NameSpace= "System.Data "%>
<%@   Import   NameSpace= "System.Collections "%>
<%@   Import   NameSpace= "System.ComponentModel "%>
<%@   Import   NameSpace= "System.Web.SessionState "%>
<%@   Import   NameSpace= "System.Web "%>
<%@   Import   NameSpace= "System.Drawing "%>
<%@   Import   NameSpace= "System.Web.UI "%>
<%@   Import   NameSpace= "System.Web.UI.HtmlControls "%>
<%@   Import   NameSpace= "System.Web.UI.WebControls "%>
<%@   Import   NameSpace= "System.Data.SqlClient "%>
<script   language= "c# "   runat= "server ">
void   Page_Load(object   sender,   System.EventArgs   e)
{
  if(!IsPostBack)
BindData();
}
private   void   BindData()
{
//使用Connection对象连接数据库
  SqlConnection   thisConnection   =   new   SqlConnection(@ "workstation   id=GINAGAO;packet   size=4096;integrated   security=SSPI;data   source= 'GINAGAO\GINAGAO ';persist   security   info=False;initial   catalog=GinaSky ");

//创建访问数据表的DataAdapter对象
  string   queryStr   =   "select   count(*)   from   Register ";
SqlDataAdapter   adapter   =   new   SqlDataAdapter(queryStr,thisConnection);
                      DataSet   myDataSet=new   DataSet();
adapter.Fill(myDataSet, "Register ");
      if(myDataSet.Tables[ "Register "].Rows.Count!=0)
{
          DataGrid1.DataSource=myDataSet.Tables[ "Register "].DefaultView;
          DataGrid1.DataBind();
}
else
{
  string   strJs1   =   " <script> window.open( 'http://www.sina.com.cn ', 'newwindow ', 'height=300,width=250 '); < "+ "/ "+ "script> "   ;
        Response.Write(strJs1);
}
}
</script>

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 查看所有已注册信息 </title>
<style   type= "text/css ">
<!--
body   {
background-color:   #000000;
}
.STYLE1   {color:   #9999FF}
-->
</style> </head>

<body>
<form   ID= "GinaForm "   method= "post "   runat= "server "   >
    <table   width= "971 "   height= "105 "   border= "0 ">
        <tr>
            <td   height= "101 "   colspan= "2 "   background= "../yuqing/15.gif "> &nbsp; </td>