SQL数据访问循环/编辑/更新 [英] SQL Data Access Loop/Edit/Update

查看:96
本文介绍了SQL数据访问循环/编辑/更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

长时间读者,第一次海报! ;)



我已经编程了很长时间,机器代码,汇编程序,基本,fortran,rpg你命名它,现在重新访问vb.net因为vb6的问题......到目前为止,我对.net的体验......好......超出了描述!



希望有人可以给我一些指针并保存我留下的几根头发!



在vb6中,我曾经做过以下事情:

Long time reader, first time poster! ;)

I've been programming for a long long time, machine code, assembler, basic, fortran, rpg you name it, now revisiting vb.net because of issues with vb6... and so far my experience with .net is .... well .... beyond description!

Hope someone can give me a few pointers and save what few hairs i have left!

In vb6 I used to do something to the effect of:

with rs '(recordset = sql is essentially 'Select * from table')
  while not .eof
    if .field("whatever")="something"
      .field("whatever")="something else"
      .update
    end if
   .movenext
wend





上面的代码(通过剥离)用于遍历表中的每条记录并允许我运行检查各个字段,根据需要进行更正并转到下一条记录。从我在.net中看到的更新是通过sql语句完成的,在我的情况下需要更多编码......我希望还有另一种方法可以做到这一点......是吗?



The code above (through stripped down) used to run through every record in a table and allow me to run checks on various fields, make corrections if needed and move on to the next record. From what i've seen in .net updates are done via sql statements which in my case would require a ton more coding ... my hope is there is another way to do this... yes?

推荐答案

这就是问题,最好的方法是什么(示例代码可以帮助或指向一个方向)。

我在网上查了一切需要一个sql语句如下...

Well that was the question, what's the best way to do this (sample code would help or a pointer in a direction).
Everything i've checked online requires an sql statement as below...
cmd = New SqlCommand("INSERT INTO Options([Field1],[Field2],[Field3]) Values (@Field1, @Field2, @Field3)")
cmd.Connection = db.conn
With cmd.Parameters
    .AddWithValue("@Field1", Field1)
    .AddWithValue("@Field2", Field2)
    .AddWithValue("@Field3", Field3)
End With





以上代码是我在原始声明中所指的'更新需要sql语句'....



此外,感谢您的链接,现在查看它(并将需要一些时间)但相信它基本上和我到处都看到的相同。一个或另一个,不是像我原来的代码一样在一个地方。

-------------------------- -------------------------------------------------- ------------------

更新:刚检查出页面/代码示例,根据代码调用Inline sql。

在快速视图之后,给出的代码函数几乎没用,因为它们被硬编码为传递的字段数,对我来说,您需要为每个表和每个可能的组合编写函数(或者传递数组)



如果这是我需要做的最简化的编码,几乎解释了M



The code above is what i was referring to in my original statement 'updates require an sql statement' ....

Also, Thanks for the link, looking at it now (and will take a bit to go through) but believe it is essentially the same as i've seen everywhere. One or the other, not all in a single place like my original code.
----------------------------------------------------------------------------------------------
Updated: Just checked out the page/code samples, according to the code it's called Inline sql.
After a 'quick' view, the code functions given are pretty much useless as they are hard coded to the number of fields passed, to me, you would need to code a function for each table and every possible combination (or pass an array)

If this is the most streamlined coding for what I need to do, pretty much explains all the issues with M

的所有问题

产品所需的大小和资源呈指数级增长!



但是要欣赏快速回复和指向示例代码的指针!
products the exponential increase in size and resource required!

But do appreciate the quick reply and the pointer to the sample code!

这篇关于SQL数据访问循环/编辑/更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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