How to enter the data based on the availablity of the data into access from VB .Net
<p>How to enter the data based on the availablity of the data into access from VB .Net</p>

<p>I'm working on a code which is to Insert the data into Access Database. I'm successfully able to do that but there are few exceptions which I don't know how to handle. So Please help me out</p>

<p>The Thing is I have 11 Text Boxes. All of those are mandatory but one text box (TextBox3) is optional. I mean, sometimes there'll be data in TextBox3 and sometimes not. Based on the availability of the data in Textbox3 I should be able to update my access database.</p>

<p>This is my code</p>

<pre><code>Imports System.Data.OleDb
Public Class Form1
    Dim provider As String
    Dim datafile As String
    Dim connString As String
    Dim myConnection As OleDbConnection = New OleDbConnection
    Dim str As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
        datafile = "D:\Database\sampletest.accdb"
        connString = provider &amp; datafile
        myConnection.ConnectionString = connString
        myConnection.Open()
        Dim insrt0 As String
        insrt0 = "Insert into 01bkDetails([bk01],[bk02],[bk03],[bk04],[bk05],[bk06],[bk07],[bk08],[bk09],[bk10],[bk11]) Values (?,?,?,?,?,?,?,?,?,?,?)"
        Dim cmd1 As OleDbCommand = New OleDbCommand(insrt0, myConnection)
             cmd1.Parameters.Add(New OleDbParameter("bk01", CType(Textbox1.Text, String)))
             cmd1.Parameters.Add(New OleDbParameter("bk02", CType(Textbox2.Text, String)))
             cmd1.Parameters.Add(New OleDbParameter("bk03", CType(Textbox3.Text, String)))
             cmd1.Parameters.Add(New OleDbParameter("bk04", CType(Textbox4.Text, String)))
             cmd1.Parameters.Add(New OleDbParameter("bk05", CType(Textbox5.Text, String)))
             cmd1.Parameters.Add(New OleDbParameter("bk06", CType(Textbox6.Text, String)))
             cmd1.Parameters.Add(New OleDbParameter("bk07", CType(Textbox7.Text, String)))
             cmd1.Parameters.Add(New OleDbParameter("bk08", CType(Textbox8.Text, String)))
             cmd1.Parameters.Add(New OleDbParameter("bk09", CType(Textbox9.Text, String)))
             cmd1.Parameters.Add(New OleDbParameter("bk10", CType(Textbox10.Text, String)))
             cmd1.Parameters.Add(New OleDbParameter("bk11", CType(Textbox11.Text, String)))
        Try
            cmd1.ExecuteNonQuery()
            cmd1.Dispose()
            myConnection.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class
</code></pre>

<p>I know that the code to check if there's data or not in a text box is this....</p>

<pre><code>If (Not String.IsNullOrWhiteSpace(Textbox3.Text)) Then

        End If
</code></pre>

<p>And I know that this code should be executed at this point <code>cmd1.ExecuteNonQuery()</code></p>

<p>My question is What should i write in between "IF" and "End IF"... Because I want only the Textbox 3 should be affected and not the remaining textboxes.</p>

<p>And I also want to know if i can have an empty field in the Access Database or is it mandatory to fill it with some data</p>

<p>Thank You.`</p>