保存并更新 [英] Save & Update

查看:59
本文介绍了保存并更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我正在vb.net 2005中创建具有ms访问权限的Windows应用程序.
在保存功能中,我正在编写以下代码::


Hie!

I am creating a windows application in vb.net 2005 with ms access.
in save function i am writing following code::


cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\panchani\Documents\Visual Studio 2005\Transport.mdb")
        cn.Open()

        str = "insert into Item_Master([item code],[item name],quantity,weight,[unit of measurement]) values(" & Val(cmbCode.Text) & ",'" & cmbName.Text & "'," & Val(txtWeight.Text) & "," & Val(txtQuantity.Text) & ",'" & txtUnit.Text & "')"
        cmd = New OleDbCommand(str, cn)
        cmd.ExecuteNonQuery()
        MsgBox("Record Inserted !")

        cn.Close()




在此代码中,我想添加一个从记录移至记录的记录集,以便我可以找到文件末尾,以便我可以插入新记录或没有eof,然后可以更新以前的记录....请帮助我!




in this code i want to add one recordset who move from record to record so i can find there is end of file so i can insert a new record or there no eof then i can update the previous record.... please help me!

推荐答案

鉴于我将解雇编写此代码的任何人,我认为它不会在现实世界中使用,只是有太多的问题.因此,我认为这是针对一堂课的.您最好与您的老师谈谈您被困的地方.但是,总的来说,我想您想让数据层检查您输入的代码是否存在(这是一个SQL调用),如果存在,则要进行更新,否则您要进行插入.假设项目代码是记录唯一的字段.
Given that I''d fire anyone who wrote this code, I assume it''s not going to be used in the real world, it''s just got too many issues. So, I assume this is for a class. You would do best to talk to your teacher about where you are stuck. However, in general, I would imagine you want your data layer to check if the code you''ve entered exists, which is a SQL call, then if it does, you want to do an update, otherwise you want to do an insert. That''s assuming that the item code is the field that is unique to a record.


这篇关于保存并更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆