不返回任何基本表信息的select命令 [英] selectcommand that does not return any base table information

查看:92
本文介绍了不返回任何基本表信息的select命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,
我进行更改并更新时出现问题,然后获取异常 select命令,该命令不返回任何基本表信息
我的代码是

sir ,
I have the problem to update the database, when i make changes and then in get the exception selectcommand that does not return any base table information
My code is

Imports System.Data.SqlClient

Public Class Form1

    Dim connetionString As String

    Dim connection As SqlConnection

    Dim adapter As SqlDataAdapter

    Dim cmdBuilder As SqlCommandBuilder

    Dim ds As New DataSet

    Dim changes As DataSet

    Dim sql As String

    Dim i As Int32



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"

        connection = New SqlConnection(connetionString)

        Sql = "select * from Product"

        Try

            connection.Open()

            adapter = New SqlDataAdapter(Sql, connection)

            adapter.Fill(ds)

            connection.Close()

            DataGridView1.Data Source= ds.Tables(0)

        Catch ex As Exception

            MsgBox(ex.ToString)

        End Try

    End Sub



    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Try

            cmdBuilder = New SqlCommandBuilder(adapter)

            changes = ds.GetChanges()

            If changes IsNot Nothing Then

                adapter.Update(changes)

            End If

            MsgBox("Changes Done")

        Catch ex As Exception

            MsgBox(ex.ToString)

        End Try

    End Sub

End Class


请帮帮我


[edit]已添加代码块-OriginalGriff [/edit]


Please help me


[edit]Code block added - OriginalGriff[/edit]

推荐答案

您需要定义命令,然后执行命令生成器.

从这里开始: MSDN:使用CommandBuilders(ADO.NET)生成命令 [ ^ ]
You need to define commands and then execute command builder.

Start from here: MSDN: Generating Commands with CommandBuilders (ADO.NET)[^]


这篇关于不返回任何基本表信息的select命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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