为什么显示是Update 无法找到 TableMapping['Table'] 或 DataTable“Table”,求大神
代码ImportsSystem.DataImportsSystem.Data.SqlClientPublicClassForm1DimconnstrAsString="D...
代码
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim connstr As String = "Data Source=pc-20140831ptoa;Initial Catalog=student;Integrated Security=True"
Dim conn As New SqlConnection(connstr)
Dim da3 As SqlDataAdapter
Dim ds3 As DataSet
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim sql2 = "select DISTINCT 课程名称,课程性质,考试形式,考勤权重,作业权重,实验权重,平时成绩权重,考试成绩权重 from 课程权重 where 教师编号=1001 " 'and 课程名称= '" + ComboBox1.Text.Trim() + "'
Dim cmd2 As New SqlCommand(sql2, conn)
da3 = New SqlDataAdapter()
da3.SelectCommand = cmd2
da3.SelectCommand.Connection = conn
ds3 = New DataSet()
da3.Fill(ds3, "课程权重")
DataGridView1.DataSource = ds3.Tables("课程权重")
DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
DataGridView1.AutoResizeColumns()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Try
If ds3.HasChanges Then
da3.Update(ds3.GetChanges)
DataGridView1.CurrentCell = DataGridView1.Rows(0).Cells(0)
MessageBox.Show("修改成功!")
Else
DataGridView1.CurrentCell = DataGridView1.Rows(0).Cells(0)
MessageBox.Show("无修改的内容!")
End If
' Catch ex As Exception
' MessageBox.Show("修改出错!")
' End Try
End Sub
End Class
是因为ds数据集没有传递下来吗,怎样才能传递 展开
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim connstr As String = "Data Source=pc-20140831ptoa;Initial Catalog=student;Integrated Security=True"
Dim conn As New SqlConnection(connstr)
Dim da3 As SqlDataAdapter
Dim ds3 As DataSet
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim sql2 = "select DISTINCT 课程名称,课程性质,考试形式,考勤权重,作业权重,实验权重,平时成绩权重,考试成绩权重 from 课程权重 where 教师编号=1001 " 'and 课程名称= '" + ComboBox1.Text.Trim() + "'
Dim cmd2 As New SqlCommand(sql2, conn)
da3 = New SqlDataAdapter()
da3.SelectCommand = cmd2
da3.SelectCommand.Connection = conn
ds3 = New DataSet()
da3.Fill(ds3, "课程权重")
DataGridView1.DataSource = ds3.Tables("课程权重")
DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
DataGridView1.AutoResizeColumns()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Try
If ds3.HasChanges Then
da3.Update(ds3.GetChanges)
DataGridView1.CurrentCell = DataGridView1.Rows(0).Cells(0)
MessageBox.Show("修改成功!")
Else
DataGridView1.CurrentCell = DataGridView1.Rows(0).Cells(0)
MessageBox.Show("无修改的内容!")
End If
' Catch ex As Exception
' MessageBox.Show("修改出错!")
' End Try
End Sub
End Class
是因为ds数据集没有传递下来吗,怎样才能传递 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏5(财富值+成长值)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询