首页 > 数据库 > 数据库开发技术 > 实战Visual C#数据库编程之五(转)
| protected void Insert_record ( object sender , System.EventArgs e ) { try { file://判断所有字段是否添完,添完则执行,反之弹出提示 if ( t_id.Text != "" && t_xm.Text != "" && t_xb.Text != "" && t_nl.Text != "" && t_books.Text != "" ) { string myConn1 = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = db.mdb" ; OleDbConnection myConn = new OleDbConnection ( myConn1 ) ; myConn.Open ( ) ; string strInsert = " INSERT INTO person ( id , xm , xb , nl , zip ) VALUES ( " ; strInsert += t_id.Text + ", '" ; strInsert += t_xm.Text + "', '" ; strInsert += t_xb.Text + "', " ; strInsert += t_nl.Text + ", " ; strInsert += t_books.Text + ")" ; OleDbCommand inst = new OleDbCommand ( strInsert , myConn ) ; inst.ExecuteNonQuery ( ) ; myConn.Close ( ) ; myDataSet.Tables [ "person" ] . Rows [ myBind.Position ] . BeginEdit ( ) ; myDataSet.Tables [ "person" ] . Rows [ myBind.Position ] . EndEdit ( ) ; myDataSet.Tables [ "person" ] . AcceptChanges ( ) ; } else { MessageBox.Show ( "必须填满所有字段值!" , "错误!" ) ; } } catch ( Exception ed ) { MessageBox.Show ( "保存数据记录发生 " + ed.ToString ( ) , "错误!" ) ; } } |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8781179/viewspace-924583/ ,如需转载,请注明出处,否则将追究法律责任。