Using this code i cannot insert data in the database . it gives no error but no row is created in the data base
Code:
Imports System.Data.SqlClient
Public Class Form1
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Initial Catalog=Database1;Integrated Security=True;User Instance=True")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If con.State = ConnectionState.Open Then
con.Close()
End If
Try
If RichTextBox1.Text.Length = 0 Then
MsgBox("MemId field cannot be empty insert value")
Else
con.Open()
Dim instr As String = "INSERT INTO member VALUES('" + RichTextBox1.Text + "','" + RichTextBox2.Text + "','" + RichTextBox3.Text + "','" + RichTextBox4.Text + "','" + RichTextBox5.Text + "','" + RichTextBox6.Text + "')"
Dim cmd As New SqlCommand(instr, con)
MsgBox("Database connected successfully")
If cmd.ExecuteNonQuery() > 0 Then
Label8.Text = "*Record created successfully*"
cmd.Dispose()
End If
cmd.Dispose()
End If
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
End Sub
Comment