can you please help me to create a adding form and it will save to sql database .. pleas

post your code please

We can hep you if you help us by showing some effort

Imports System.Data.SqlClient


Public Class Form7



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

        Dim check As Integer
        Dim conn As New SqlConnection
        Dim cmd As New SqlCommand
        Dim cmd1 As New SqlCommand
        Dim da As New SqlDataAdapter
        Dim ds As New DataSet
        Dim dt As New DataTable


        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Then
            MsgBox("Admin Data is not completed", MsgBoxStyle.OkOnly)
        Else
            If MsgBox("Are you sure to save Admin data with Id : " & TextBox1.Text & " ?", MsgBoxStyle.OkCancel, "Input confirm") = MsgBoxResult.Cancel Then
                ' do nothing
            Else
                Try
                    conn = GetConnect()
                    conn.Open()
                    cmd = conn.CreateCommand
                    cmd.CommandText = "SELECT * FROM admin WHERE id='" & Trim(TextBox1.Text) & " ' "
                    da.SelectCommand = cmd
                    da.Fill(ds, "admin")
                    dt = ds.Tables("admin")

                    If (dt.Rows.Count > 0) Then
                        MsgBox("ADMIN Id " & Trim(TextBox1.Text) & " is already in database", MsgBoxStyle.OkOnly, "Message :")
                    Else

                        cmd1 = conn.CreateCommand
                        cmd1.CommandText = "INSERT INTO admin(id, username, password,first_name,last_name,email_add,job) VALUES('" & Trim(TextBox1.Text) & "','" & Trim(TextBox2.Text) & "','" & Trim(TextBox3.Text) & "','" & Trim(TextBox4.Text) & "','" & Trim(TextBox5.Text) & "','" & Trim(TextBox6.Text) & "','" & Trim(TextBox7.Text) & "')"
                        check = cmd1.ExecuteReader.RecordsAffected()

                        If check > 0 Then
                            MsgBox("Student With Id " & Trim(TextBox1.Text) & " succesfully to added", MsgBoxStyle.OkOnly, "Message :")
                        Else
                            MsgBox("Student With Id " & Trim(TextBox1.Text) & " Failure  to added", MsgBoxStyle.OkOnly, "Message :")
                        End If
                        conn.Close()

                    End If

                Catch ex As Exception
                    'MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
                End Try
            End If
        End If
    End Sub


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

        Form6.Show()
        Me.Close()

    End Sub

    Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim conn As New SqlConnection("Data Source=CUBED-DESKTOP05;Initial Catalog=CubedTime;Integrated Security=True")
        Dim cmd As New SqlCommand
        Dim da As New SqlDataAdapter
        Dim ds As New DataSet
        Dim dt As New DataTable
        Dim cmb As New SqlCommandBuilder

        'clear all textbox
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        'this part to call data from database and show in datagrid
        conn = GetConnect()
        Try
            cmd = conn.CreateCommand
            cmd.CommandText = "SELECT * FROM admin"
            da.SelectCommand = cmd
            da.Fill(ds, "admin")
            dg.DataSource = ds.Tables("admin")
            dg.DataMember = "admin"
            dg.ReadOnly = True
        Catch ex As Exception
            'MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
        End Try


    End Sub

    Private Function GetConnect() As SqlConnection
        Throw New NotImplementedException
    End Function

End Class

THIS IS MY CODE help me pls

change

check = cmd1.ExecuteReader.RecordsAffected()

to this

check = cmd1.ExecuteNonQuery()
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.