首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

大伙儿看看下面语句错。Dataset填充SQL表

2011-12-17 
大家看看下面语句错。。Dataset填充SQL表stringfile~/uploadfiles/ +DropDownList1.TextstringConStrP

大家看看下面语句错。。Dataset填充SQL表
string   file   =   "~/uploadfiles/ "   +DropDownList1.Text;    
                string   ConStr   =   "Provider=Microsoft.Jet.OLEDB.4.0; "   +   "   Data   Source= "   +   Server.MapPath(file)   +   ";   Extended   Properties=Excel   8.0; ";
                OleDbConnection   Conn   =   new   OleDbConnection(ConStr);
                Conn.Open();
                OleDbCommand   Comm   =   new   OleDbCommand( "select   *   from   [Sheet1$] ",   Conn);
                OleDbDataAdapter   ad   =   new   OleDbDataAdapter();
                ad.SelectCommand   =   Comm;
                DataSet   ds   =   new   DataSet();
                ad.Fill(ds,   "xls ");
                OleDbCommandBuilder   cb   =   new   OleDbCommandBuilder(ad);
                ad.Update(ds,   "xls ");
                GridView1.DataSource   =   ds;
                GridView1.DataBind();    
                //以上都是正确的
                string   connstr   =   System.Configuration.ConfigurationSettings.AppSettings[ "connstring "];
                SqlConnection   con   =   new   SqlConnection(connstr);
                con.Open();              
            string   strcom1   =   "create   table   ' "+DropDownList1.Text+ " ' ";
                SqlCommand   mycom1=new   SqlCommand(strcom1,con);
                mycom1.ExecuteNonQuery();            
                Response.Write( " <script> alert( '新建了一个表! ');location= 'javascript:history.go(-1) ' </script> ");

                    for(int   i=0;i <   ds.Table[0].Rows.Count;i++)
                {
                  string   str=ds.Table[0].Rows[i][1].ToString();
                  string   sqlstr= "insert   into   book   values   ( ' "+str+ " ') ";
                    SqlCommand   com2   =   new   SqlCommands(sqlstr,   con);
                  com2.ExecuteNonQuery();
                       
                }


                con.Close();
                        Response.Write( " <script   language=javascript> alert( '添加成功! ') </script> ");

//以下错误地方
编译器错误信息:   CS0117:   “System.Data.DataSet”并不包含“Table”的定义

源错误:

 

行   49:                   Response.Write( " <script> alert( '新建了一个表! ');location= 'javascript:history.go(-1) ' </script> ");
行   50:  
行   51:                       for(int   i=0;i <   ds.Table[0].Rows.Count;i++)
行   52:                   {
行   53:                     string   str=ds.Table[0].Rows[i][1].ToString();
 


[解决办法]
up
[解决办法]
ds.Table[0]
是不是少了个s啊?
ds.Tables[0]
[解决办法]
哈哈楼上看的真细心
[解决办法]
string sqlstr= "insert into book values ( ' "+str+ " ') ";
SqlCommand com2 = new SqlCommand(sqlstr, con);
com2.ExecuteNonQuery();

是这里的错误,表book可能不只一列,其他列没有指定值。
[解决办法]
你建表的时候声明列了吗????

热点排行