how can validate empty data for text fields... i want to validate fields before inserting into database

Plz explain the question in more detail..Only then somebody will able to answer u..Ur question is not clear

Plz explain the question in more detail..Only then somebody will able to answer u..Ur question is not clear

I have some text filed on forms. i want that when a new record is to be inserted into database and user clicks on add/save button then validation check should be made to see that all necessary fileds are filled and not empty. If any one is empty then a message is needed to be displayed..
Thanks

ok.It so easy frnd..Supose i have one textbox and on button click i m inserting the data..I want that when textbox is blank,Then msg is there..Please enter the text and record is not inserted into the database.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Trim(TextBox1.Text) = "" Then
            MsgBox("Please Enter the text")
            Exit Sub
        End If

        Call InsertData()
    End Sub

    Private Sub InsertData()
 'Do Ur Coding Here
    End Sub

Now if textbox is blank .when user clicks on button,msg is dere....

maheen plz dont post same question more than once....U put this same question twice.

ok.It so easy frnd..Supose i have one textbox and on button click i m inserting the data..I want that when textbox is blank,Then msg is there..Please enter the text and record is not inserted into the database.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Trim(TextBox1.Text) = "" Then
            MsgBox("Please Enter the text")
            Exit Sub
        End If

        Call InsertData()
    End Sub

    Private Sub InsertData()
 'Do Ur Coding Here
    End Sub

Now if textbox is blank .when user clicks on button,msg is dere....

Also, if you're looking for text in multiple textboxes then you can use an AND operator :

If txtBox1.text = ""  [b]or[/b] txtBox2.text = "" Then
            MsgBox("Please Enter the text")
            Exit Sub
        End If

        Call InsertData()

if either textbox.text is empty, the messagebox will be displayed

Comparing a string to "" actually compares with a string which has a length of zero. This is not the same thing as an empty string. Use instead String.IsNullOrEmpty() to test both cases

If String.IsNullOrEmpty(TextBox1.Text) OrElse String.IsNullOrEmpty(TextBox2.Text) Then
  MsgBox("Please Enter the text")
  Exit Sub
End If

If you want to compare more than one strings at the same time, use OrElse instead of Or. OrElse uses a C-style "shortcut evaluation" i.e. if the first value is true then it won't evaluate next expression. Ok, that's a small "optimization" and in practice has no noticeable effect in the speed of your code. But using OrElse sometimes reveals logical errors in you code.

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.