this is my code i dose not work: ( help me i am create for new user from VB with access)

Public Class newuserForm

Private Sub btncreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncreate.Click

    If txtword.Text = "" Or txtid.Text = "" Then
        MessageBox.Show("Please complete the required fields..", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Else

        Dim Conn As System.Data.OleDb.OleDbConnection

        Dim ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\Database1.accdb"
        Conn = New System.Data.OleDb.OleDbConnection(ConnectionString)

        Try
            Dim sql As String = "insert into tbl_datain ([UserID], [PassWord]) values( " & txtid.Text & " , " & txtword.Text & " ')"
            Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql, Conn)

            sqlCom.Connection = Conn
            Conn.Open()

            Dim sqlRead As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader(sql)

            If sqlRead.Read() Then
                MessageBox.Show("Success created")
            Else

                MessageBox.Show("You already in", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

                txtid.Text = ""
                txtword.Text = ""

                txtid.Focus()
            End If
        Catch ex As Exception

            MessageBox.Show("Failed to connect to Database..", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)


        End Try
    End If
    end sub
    end class

Haaaaaaaaaaaaa!, What a madly codes you have done.
You tried to create a new user, but before creating it you went to check, is it has or not? Think deeply and widely what will you have to do? Time of codifications you can do any type of mistakes (this is permisible and acceptable), but this type of mistakes always block your thinking. You never find what mistake you did?

Finally
You created a SQL Statement to insert a new user. How did you use it to find the user in data table?
There is a wrong in your Insert Statement. You did not put a ' in apropriate position.
Here I am trying to modify yours.

 Private Sub btncreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncreate.Click
        If String.IsNullOrWhiteSpace(txtword.Text) Or String.IsNullOrWhiteSpace(txtid.Text) Then
            MessageBox.Show("Please complete the required fields..", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If

        Dim Conn As System.Data.OleDb.OleDbConnection
        Dim ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\Database1.accdb"
        Conn = New System.Data.OleDb.OleDbConnection(ConnectionString)


        Try
            If Conn.State = ConnectionState.Open Then Conn.Close()
            Conn.Open()

            Dim sql As String = "insert into tbl_datain ([UserID], [PassWord]) values('" & txtid.Text & "', '" & txtword.Text & "')"
            Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql, Conn)
            sqlCom.Connection = Conn

            Dim result As Integer = sqlCom.ExecuteNonQuery()

            sqlCom.Dispose()
            Conn.Close()

            If result > 0 Then
                MessageBox.Show("Successfully created.")
            Else
                MessageBox.Show("Failure to create.")
            End If

            txtid.Text = ""
            txtword.Text = ""
            txtid.Focus()

        Catch ex As Exception
            MessageBox.Show("Failed to connect to Database..", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try


    End Sub

Suppose it can help you.

oh is it very badly my code becouse i did also ask my friends they say the code is corrct dun why cant work...!!haha..!!

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.