如果我只使用.Fill命令,如何更新Sql Server? [英] How do I Update Sql Server if I have only used .Fill commands ?

查看:78
本文介绍了如果我只使用.Fill命令,如何更新Sql Server?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,只需单击一个按钮即可执行...我知道它可能编码效率低,效率低,但我只是想在我担心性能和命名标准之前让逻辑工作。无论如何,在我阅读并选择了我想要的文件夹后,如何使用我选择的新路径更新SQL Server表?



 私有  Sub  Button3_Click(发件人 As  System。 Object ,e  As  System.EventArgs)句柄 Button3.Click 

Dim folderBrowserDialog As FolderBrowserDialog()

myPath = Environment.SpecialFolder.MyComputer

Me .FileLocationsTableAdapter1.Fill( Me .KickaboutEmailDataSet1.FileLocations)

For 每个 Dr As 数据Row In KickaboutEmailDataSet1.FileLocations.Rows
myPath = Dr.Item( 1 )。ToString
下一步

folderBrowserDialog.Description = 选择存储调度计划文件的文件夹
folderBrowserDialog.RootFolder = myPath
folderBrowserDialog.ShowNewFolderButton = True

如果 folderBrowserDialog.ShowDialog()= Windows.Forms.DialogResult.OK 那么
myPath = folderBrowserDialog.SelectedPath
否则
退出 Sub
结束 如果

>>>现在我需要 更新数据库 new 路径<<<


结束 Sub

解决方案

你应该担心从一开始就命名标准,否则你永远都不会做对。随着时间的推移,您还可以学习如何编写更高性能的代码。



您首先如何使用数据库?如果您正在学习,实体框架是最容易使用的,您不需要一开始就学习SQL。你的选择是



1 - EF(最简单)

2 - 存储过程

3 - 一个参数查询

I have the following code that executes on the click of a Button ... I know it's probably poor coding and inefficient, but I am just trying to get my logic working before I worry about performance and naming standards. Anyway, after I have read and selected the Folder I want, how do I update the SQL Server Table with the new Path I've selected ?

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click

     Dim folderBrowserDialog As New FolderBrowserDialog()

     myPath = Environment.SpecialFolder.MyComputer

     Me.FileLocationsTableAdapter1.Fill(Me.KickaboutEmailDataSet1.FileLocations)

     For Each Dr As DataRow In KickaboutEmailDataSet1.FileLocations.Rows
         myPath = Dr.Item(1).ToString
     Next

     folderBrowserDialog.Description = "Select Folder Where Despatch Schedule File is Stored"
     folderBrowserDialog.RootFolder = myPath
     folderBrowserDialog.ShowNewFolderButton = True

     If folderBrowserDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
         myPath = folderBrowserDialog.SelectedPath
     Else
         Exit Sub
     End If

    >>> Now I need to update the Database with the new Path <<<


 End Sub

解决方案

You should worry about naming standards from the start, or you'll never get it right. Over time, you can also learn how to write more performant code.

How are you using the DB in the first place ? If you're learning, Entity Framework is what is easiest to work with, you won't need to learn SQL for a start. Your options are

1 - EF ( easiest )
2 - stored procs
3 - a paramaterised query


这篇关于如果我只使用.Fill命令,如何更新Sql Server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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