一个小程序 
点击按钮执行插入一行,程序运行没有错误,但打开数据库发现并没有插入,请问为什么?片断如下:private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                db1DataSet.wordRow newRow = db1DataSet1.word.NewwordRow();                newRow["word"] = "1234";                
                newRow["means"] = "4534";
                newRow["ok"] = false;
                newRow["ord"] = 3;                db1DataSet1.word.Rows.Add(newRow);                               
                wordTableAdapter1.Update(db1DataSet1); 
            }
            catch (Exception e1)
            {
                Console.WriteLine(e1.ToString());
            }
        }谢谢大家!

解决方案 »

  1.   

    public static void  InSertDB()
    {
    SqlConnection con = DB.CreateDBcon();
    string sql="插入语句"
    con.Open();
    SqlCommand cmd=new SqlCommand(sql,con);
    try
    {
    cmd.ExecuteNonQuery();
    writeFile(newId);
    }
    catch
    {
    Console.Write("插入出错了");
    }
    finally
    {
    cmd.Dispose();
    con.Close();
    } }
      

  2.   


                      public static void  InSertDB()//多写了一点
    {
    SqlConnection con = DB.CreateDBcon();
    string sql="插入语句";
    con.Open();
    SqlCommand cmd=new SqlCommand(sql,con);
    try
    {
    cmd.ExecuteNonQuery();
    }
    catch
    {
    Console.Write("插入出错了");
    }
    finally
    {
             cmd.Dispose();
             con.Close();
    } }