我有以下完美执行的代码,但DataTable没有更新......我错过了什么/做错了什么?!
Option Compare Text
Option Explicit On
Imports System
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows
Imports System.Windows.Forms
Imports Microsoft.Office
Imports Microsoft.Office.Interop
Public Class Form1
Public txtTo As String = ""
Public txtFrom As String = ""
Public txtSubject As String = ""
Public txtBody As String = ""
Public txtAttachmentID As String = ""
Public txtAttachment As String = ""
Public MsgBoxResult As DialogResult
Public myPath As String = ""
Public dbLeague As String = ""
Public dbSession As String = "3"
Public Sqlstring As String = ""
Public myText As String
Public newLocationRow As KickaboutEmailDataSet.FileLocationsRow
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.LeaguesTableAdapter1.Fill(Me.KickaboutEmailDataSet1.Leagues)
ComboBox1.SelectedIndex = -1
ComboBox2.SelectedIndex = 0
End Sub
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)
If File.Exists(myPath & "\Despatch Schedule.txt") Then
myText = ""
Else
myText = "to be "
End If
For Each Dr As DataRow In KickaboutEmailDataSet1.FileLocations.Rows
myPath = Dr.Item(1).ToString
Next
folderBrowserDialog.Description = "Select Folder Where Despatch Schedule File is " & myText & "Stored"
folderBrowserDialog.RootFolder = myPath
folderBrowserDialog.ShowNewFolderButton = True
If folderBrowserDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
myPath = folderBrowserDialog.SelectedPath
Else
Exit Sub
End If
我已经使用MSDN作为我的指南编写了接下来的四行,正如我所说,它们执行得很好,但数据库没有得到更新<<
newLocationRow = KickaboutEmailDataSet1.FileLocations.NewFileLocationsRow()
newLocationRow.ID = 0
newLocationRow.DESPATCHSCHEDULE = myPath
KickaboutEmailDataSet1.FileLocations.Rows.Add(newLocationRow)
End Sub
End Class
答案 0 :(得分:0)
只需创建一个DataAdapter实例(SqlDataAdapter,如果您使用的是Sql Server)并调用Update ...也许您已经有了一个可用的DataAdapter,因为您似乎正在使用类型化数据集......