| |

VerySource

 Forgot password?
 Register
Search
View: 1068|Reply: 10

Update the data set

[Copy link]

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-22 21:00:02
| Show all posts |Read mode
Private Sub updata_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updata.Click
        imagepath = Application.StartupPath + "\face\" + data.Tables (0) .Rows (0) .Item (6) + ".bmp"
        a = a.FromFile (imagepath)
              Else
            Try
                Dim strsql As String = "update cardinfo set (name = @ name, old = @ old, number = @ number, address = @ address, mail = @ mail)"
                Dim strcmd As New SqlCommand (strsql, sqlconn)
                With data.Tables (0) .Rows (0)
                    .Item (0) .Parameters.Add (New SqlParameter ("@ name", SqlDbType.VarChar)). Value = nametxt.Text
                    .Item (2) .Parameters.Add (New SqlParameter ("@ old", SqlDbType.Int)). Value = old.Text
                    .Item (4) .Parameters.Add (New SqlParameter ("@ number", SqlDbType.VarChar)). Value = number.Text
                    If man.Checked.ToString = "Male" Then
                        .Item (1) .Parameters.Add (New SqlParameter ("@ sex", SqlDbType.VarChar)). Value = "Male"
                    Else: .Item (1) .Parameters.Add (New SqlParameter ("@ sex", SqlDbType.VarChar)). Value = "Female"
                    End If
                    .Item (3) .Parameters.Add (New SqlParameter ("@ address", SqlDbType.VarChar)). Value = address.Text
                    .Item (5) .Parameters.Add (New SqlParameter ("@ mail", SqlDbType.VarChar)). Value = mail.Text
                End With
                strcmd.CommandType = CommandType.Text
                sqlconn.Open ()
                strcmd.ExecuteNonQuery ()
                strcmd.CommandType = CommandType.Text
                cardada.SelectCommand = strcmd
                cardada.Update (data)
                sqlconn.Close ()
                MessageBox.Show ("Update successful", "Status", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Catch sqlexc As SqlException
                MessageBox.Show (sqlexc.ToString, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End Try
        End If
    End Sub
Let me see it. Why, I run to .Item (0) .Parameters.Add (New SqlParameter ("@ name", SqlDbType.VarChar)). Value = nametxt.Text
Prompt: Public member "Parameters" of type "String" was not found.
So painful. Who's pointing
Reply

Use magic Report

0

Threads

48

Posts

30.00

Credits

Newbie

Rank: 1

Credits
30.00

 China

Post time: 2020-7-1 11:45:01
| Show all posts
sqlparameter is used for sqlcommand, and you want to use sqlparameter
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-7-1 14:45:01
| Show all posts
data.Tables(0).Rows(0).Item(0).Parameters.Add(...)

- Is there such a usage in VB.NET?
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 Iran

Post time: 2020-7-2 13:00:01
| Show all posts
should be
strcmd.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = nametxt.Text
....
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-5 17:00:02
| Show all posts
Thank you, but I changed it
Try
            Dim strsql As String = "update cardinfo set name=@name,old=@old,sex=@sex,number=@number,address=@address,mail=@mail"
            Dim strcmd As New SqlCommand(strsql, sqlconn)
            With strcmd
                .Parameters.Add(New SqlParameter("@name", SqlDbType.VarChar)).Value = nametxt.Text
                .Parameters.Add(New SqlParameter("@old", SqlDbType.Int)).Value = old.Text
                .Parameters.Add(New SqlParameter("@number", SqlDbType.VarChar)).Value = number.Text
                If man.Checked.ToString = "Male" Then
                    .Parameters.Add(New SqlParameter("@sex", SqlDbType.VarChar)).Value = "Male"
                Else: .Parameters.Add(New SqlParameter("@sex", SqlDbType.VarChar)).Value = "Female"
                End If
                .Parameters.Add(New SqlParameter("@address", SqlDbType.VarChar)).Value = address.Text
                .Parameters.Add(New SqlParameter("@mail", SqlDbType.VarChar)).Value = mail.Text
            End With
            strcmd.CommandType = CommandType.Text
            sqlconn.Open()
            strcmd.CommandType = CommandType.Text
            cardada.SelectCommand = strcmd
            strcmd.ExecuteNonQuery()
            sqlconn.Close()
            MessageBox.Show("Update Successful", "Status", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch sqlexc As SqlException
            MessageBox.Show(sqlexc.ToString, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
But the entire table is updated to a new record.
How to do it
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-5 18:30:01
| Show all posts
There is just that. VS how to add a right-click menu.
I didn’t find that control for a long time, please give pointers
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-5 18:45:01
| Show all posts
I would like to ask how to update the data set, and then return the data to the database, which brother, please write it.
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 Unknown

Post time: 2020-7-5 19:30:01
| Show all posts
Dim strsql As String = "update cardinfo set name=@name,old=@old,sex=@sex,number=@number,address=@address,mail=@mail where column name=condition"

- Of course there is no write condition to update all records
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-6 20:30:01
| Show all posts
Thank you so much. Thank you so much.
Successful, now it will not add the right-click menu.
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-7-7 08:00:01
| Show all posts
There is a menu control in WinForm which is very convenient
ASP.NET never got it
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list