I use ADO.net and SQL database . but cannot updata records into database .
Who can do it ? help me please !
my database is sv.mdf , table is huycnt include fields : id , name .
help me soon . Thanks

show use your code and effort. we will help u :)

Here is code :

Imports System.data.SqlClient
Public Class Form1
    Dim s As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=D:\csdl1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
    Dim connect As New SqlConnection(s)
    Dim da As New SqlDataAdapter
    Dim ds As New DataSet
    Dim cmd As New SqlCommand
    Dim them1 As Boolean = False
    Dim xoa As Boolean = False
    Dim sua As Boolean = False

    Private Sub exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exit.Click
        End
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       	Try
            connect.Open()
            MessageBox.Show("connect ok")
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try

    End Sub

    Private Sub showdata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles showdata.Click
        If connect.State = ConnectionState.Closed Then
            connect.Open()
        Else
            Dim s As String = "select * from huycnt"
            cmd.CommandText = s
            cmd.CommandType = CommandType.Text
            cmd.Connection = connect
            da.SelectCommand = cmd
            ds.Clear()
            da.Fill(ds, "huycnt")
            dg.DataSource = ds.Tables("huycnt").DefaultView
        End If
        connect.Close()
    End Sub

Private Sub add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles add.Click
        txtma.Focus()
    End Sub

Private Sub Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save.Click

        If connect.State = ConnectionState.Closed Then
            connect.Open()
        Else
            Dim s As String = "insert into huycnt(id,name)values ('" + txtid.Text + "', '" + txtname.Text + "')"
            cmd.CommandText = s
            cmd.CommandType = CommandType.Text
            cmd.Connection = connect
            da.SelectCommand = cmd
            da.Fill(ds, "huycnt")
            'MessageBox.Show("success ")
            da.Update(ds, "huycnt")

           
            dg.Refresh()


        End If
        connect.Close()

    End Sub
End Class

but records can not update into database . please help me

fine ya....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.