标题:【求助】 大侠们快给挑错啊
只看楼主
yangwenbo289
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-10-12
结帖率:50%
已结贴  问题点数:6 回复次数:2 
【求助】 大侠们快给挑错啊
static void Main(string[] args)
        {
            string str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Teacherdb.mdb";
            OleDbConnection conn = new OleDbConnection(str);
            conn.Open();

            string sql = "Select * from teacher";
            OleDbDataAdapter MyAdapter = new OleDbDataAdapter(sql, conn);

            MyAdapter.SelectCommand = new OleDbCommand(sql,conn);

            DataSet mydataset = new DataSet();
            MyAdapter.Fill(mydataset,"teacher");
            DataTable mytable=mydataset.Tables["teacher"];
            DataRow myrow = mytable.NewRow();
            //定义各行字段
             myrow["ID"]="109";
             myrow["Name"]="成龙";
             myrow["Sex"]="男";
             myrow["Nation"]="是";
             myrow["Age"]="55";
             myrow["Position"]="教授";
             myrow["Master"]="是";
             myrow["Tel"]="110";

             mytable.Rows.Add(myrow);
             MyAdapter.InsertCommand = new OleDbCommand("Insert into teacher (ID,Name,Sex,Nation,Age,Position,Master,Tel)"+
                 " Values ('" + myrow["ID"] + "','" +
                 myrow["Name"] + "','"+
                 myrow["Sex"] + "','"+
                 myrow["Nation"] + "','"+
                 myrow["Age"] + "','"+
                 myrow["Position"] + "','"+
                 myrow["Master"] + "',"+
                 myrow["Tel"] + ")",conn);
             Console.WriteLine(MyAdapter.());
             MyAdapter.Update(mydataset,"teacher");
             Console.WriteLine("插入成功!");
             Console.ReadLine();
        }
    }
搜索更多相关主题的帖子: sql teacher 
2011-10-27 14:30
yangwenwei
Rank: 2
等 级:论坛游民
帖 子:20
专家分:28
注 册:2011-10-24
得分:3 
怎么也不把错误提示贴出来……
2011-10-27 18:56
zzqqrr
Rank: 6Rank: 6
来 自:299294817
等 级:侠之大者
威 望:1
帖 子:155
专家分:408
注 册:2011-6-11
得分:3 
MyAdapter.SelectCommand = new OleDbCommand(sql,conn);//这句多余吗
 DataTable mytable=mydataset.Tables["teacher"];//   .tables[0];



59izk,com神奇百货,神奇百货网官网,shenqi,一个神奇的导购站!!
2011-10-29 13:31



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-353574-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.173338 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved