您的位置:首页 > 数据库

DataSet 更新到数据库

2013-07-30 23:47 288 查看
Imports System.Web.Services

Imports hhha

Imports System.Data

Imports System.Data.SqlClient

Imports System.Web.Configuration

Partial Class test_Default

    Inherits System.Web.UI.Page

    Public Function WriteDataSet() As Boolean

        Dim ws As New hhha.myWebService()

        Dim ds As DataSet

        ds = ws.GetData()

        Dim con As SqlConnection

        'gv.DataSource = ds.Tables(0)

        'gv.DataBind()

        Try

            Response.Write("333")

            Dim constring As String

            Response.Write("555")

            constring = WebConfigurationManager.ConnectionStrings("johndbtest").ConnectionString

            ' constring = "DataSource=localhost;Initial Catalog=johndbtest;user id=JohnSmith ;password=yao123"

            ' Response.Write(constring)

            Dim ds1 As DataSet = New DataSet

            con = New SqlConnection(constring)

            ' Dim da As SqlDataAdapter = New SqlDataAdapter("select * from newtable ", con)

            Dim command As SqlCommand

            con.Open()

            command = New SqlCommand("select * from dbo.newtable ", con)

            Dim da As SqlDataAdapter = New SqlDataAdapter(command)

            Dim scb As SqlCommandBuilder = New SqlCommandBuilder(da)

            da.Fill(ds1, "ntb1")

            For Each row In ds.Tables(0).Rows

                Dim nrow As DataRow

                nrow = ds1.Tables(0).NewRow

                nrow(0) = row(0)

                nrow(1) = row(1)

                nrow(2) = row(2)

                nrow(3) = row(3)

                nrow(4) = row(4)

                nrow(5) = row(5)

                nrow(6) = row(6)

                nrow(7) = row(7)

                ds1.Tables(0).Rows.Add(nrow
4000
)

            Next

            da.Update(ds1.Tables(0))

        Catch e As Exception

            Response.Write(e.Message)

        Finally

            con.Close()

            'con.Dispose()

        End Try

        ' Response.Write(ds.Tables(0).Rows(0).Item(1))

        Return True

    End Function

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

        WriteDataSet()

    End Sub

End Class
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息