Hi every one, I have a problem in inserting database entry, suppose I have two paragraph entered in one richtextbox what I want is that When I hit save, every paragraph will be save as one database entry therefore my database will have two records..

This uses VB.net 2010.

Please help....

Recommended Answers

All 17 Replies

Whats your code? do u have writen any code? do you know how to recognise the paragraphs?

You can simply break up the text by locating the relevant paragraph start points. For instance if you hit enter twice to designate a new paragraph you just need to locate the two carriage returns and line feeds in the text string.
If what defines a new paragraph isn't that clear cut you may have problems locating them.

i dont have any idea..please post some code.or a link which correspond to this thread??

Thank you..

i dont have any idea..please post some code.or a link which correspond to this thread??

Thank you..

i dont have any idea..please post some code.or a link which correspond to this thread??

Thank you..

hericles, can you show some code???

If you had 2 other textboxes this would split the text in the first textbox into paragraphs to be displayed in the other two. This splits whenever the enter key was hit which may not be exactly what you want.

Dim input As String
input = RichTextBox1.Text

Dim output As String() = input.Split(New String() {vbCr & vbLf, vbLf}, StringSplitOptions.None)

RichTextBox2.Text = output(0).ToString()
RichTextBox3.Text = output(1).ToString()

To save to the database simply go through through each item in the output array.

I only have 1 richtextbox,what I want is that when I input 2 paragraph in the richtextbox, it will save two data entry..

Kindly help...

Hi X2fair,
have you tried to understand the code given by hericles ?
No need to have one more richtextbox.
I am using the same code as given by hericles

Dim input As String
input = RichTextBox1.Text

Dim output As String() = input.Split(New String() {vbCr & vbLf, vbLf}, StringSplitOptions.None)

Loop through this array and save the values in DB. Show your code if u have doubt.

what if I have two or more paragraph??

can u show a code with complete details in saving to the database??

Thank's a lot...

Try
            Dim cnn As SqlConnection
            Dim strCnn As String = "your data base conection"
            cnn = New SqlConnection(strCnn)
            cnn.Open()
            Dim input As String
            input = TextBox1.Text

            Dim output As String() = input.Split(New String() {vbCr & vbLf, vbLf}, StringSplitOptions.None)
            If output.Length > 0 Then
                For i As Integer = 0 To output.Length - 1
                    ''here get the value of paragraph and pass to Query
                    ''Construct the Query properly.
                    Dim comm As New SqlCommand("Insert into table(column1,column2) values(value1,value2)", cnn)
                    comm.CommandType = CommandType.Text
                    comm.ExecuteNonQuery()
                Next
            End If
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub

This is just example not working module.

More paragraphs simply means a longer array.
Loop through it, doing your database insert operation on each array element. If you don't know how to do database inserts, google it. It isn't hard

If txtAddBIO.Text = "" Then
            MsgBox("Please paste BIO. Thank You.", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ERROR")
        Else
            selectmysqlquery = "SELECT `BIO_Entry` FROM `bio_db`.`bio_table` WHERE `BIO_Entry` = '" & Replace(txtAddBIO.Text, "'", "''") & "'"

            Dim connection As New MySqlConnection(connstr)
            Dim da As New MySqlDataAdapter(selectmysqlquery, connection)
            Dim ds As New DataSet()

            If da.Fill(ds) Then
                MsgBox("That BIO Already exist. Thank You!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ERROR")
            Else
                Try
                    Dim cnn As MySqlConnection
                    Dim strCnn As String = connstr ' "your data base conection"
                    cnn = New MySqlConnection(strCnn)
                    cnn.Open()
                    Dim input As String
                    input = txtAddBIO.Text

                    Dim output As String() = input.Split(New String() {vbCr & vbLf, vbLf}, StringSplitOptions.None)
                    If output.Length > 0 Then
                        For i As Integer = 1 To output.Length - 1

                            addmysqlquery = "INSERT INTO `bio_db`.`bio_table`(`BIO_Entry`,`date_added`)VALUES ('" & Replace(txtAddBIO.Text, "'", "''") & "','" & lblDateTime.Text & "')"
                            mysqlCommand(addmysqlquery)
                            PopulateDataGrid()
                        Next
                    End If
                    MsgBox("New BIO Entry Successfully save", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "SUCCESSFULL")
                    txtAddBIO.Clear()
                Catch ex As Exception
                    MessageBox.Show(ex.ToString)
                End Try

            End If
        End If
    End Sub

Check Out these codes..thats for the save button. For instance I have to insert two paragraph inside the textbox and when I hit that button, It the two paragraph in one data entry. And the database saves two data entry with the two paragraph inside the textbox..

kindly check...

please paste ur code in code tag...

If txtAddBIO.Text = "" Then
MsgBox("Please paste BIO. Thank You.", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ERROR")
Else
selectmysqlquery = "SELECT `BIO_Entry` FROM `bio_db`.`bio_table` WHERE `BIO_Entry` = '" & Replace(txtAddBIO.Text, "'", "''") & "'"

Dim connection As New MySqlConnection(connstr)
Dim da As New MySqlDataAdapter(selectmysqlquery, connection)
Dim ds As New DataSet()

If da.Fill(ds) Then
MsgBox("That BIO Already exist. Thank You!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ERROR")
Else
Try
Dim cnn As MySqlConnection
Dim strCnn As String = connstr ' "your data base conection"
cnn = New MySqlConnection(strCnn)
cnn.Open()
Dim input As String
input = txtAddBIO.Text

Dim output As String() = input.Split(New String() {vbCr & vbLf, vbLf}, StringSplitOptions.None)
If output.Length > 0 Then
For i As Integer = 1 To output.Length - 1

addmysqlquery = "INSERT INTO `bio_db`.`bio_table`(`BIO_Entry`,`date_added`)VALUES ('" & Replace(txtAddBIO.Text, "'", "''") & "','" & lblDateTime.Text & "')"
mysqlCommand(addmysqlquery)
PopulateDataGrid()
Next
End If
MsgBox("New BIO Entry Successfully save", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "SUCCESSFULL")
txtAddBIO.Clear()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try

End If
End If
End Sub

Check Out these codes..thats for the save button. For instance I have to insert two paragraph inside the textbox and when I hit that button, It the two paragraph in one data entry. And the database saves two data entry with the two paragraph inside the textbox..

kindly check...

In your code ur not asking the command to execute
ur just saying mysqlCommand(addmysqlquery)
and ur not passing the array value to Query. please verify ur code.

can you add some code in order about looping, because certainly I have no idea.

Thank's.

If txtAddBIO.Text = "" Then
            MsgBox("Please paste BIO. Thank You.", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ERROR")
        Else
            selectmysqlquery = "SELECT `BIO_Entry` FROM `bio_db`.`bio_table` WHERE `BIO_Entry` = '" & Replace(txtAddBIO.Text, "'", "''") & "'"

            Dim connection As New MySqlConnection(connstr)
            Dim da As New MySqlDataAdapter(selectmysqlquery, connection)
            Dim ds As New DataSet()

            If da.Fill(ds) Then
                MsgBox("That BIO Already exist. Thank You!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ERROR")
            Else
                Try
                    Dim cnn As MySqlConnection
                    Dim strCnn As String = connstr ' "your data base conection"
                    cnn = New MySqlConnection(strCnn)
                    cnn.Open()
                    Dim input As String
                    input = txtAddBIO.Text

                    Dim output As String() = input.Split(New String() {vbCr & vbLf, vbLf}, StringSplitOptions.None)
                    Dim bioEntry As String                    
                     If output.Length > 0 Then
                        For i As Integer = 1 To output.Length - 1
                            bioEntry = output.GetValue(i)                            addmysqlquery = "INSERT INTO `bio_db`.`bio_table`(`BIO_Entry`,`date_added`)VALUES ('" & bioEntry & "','" & lblDateTime.Text & "')"
                            mysqlCommand(addmysqlquery)
                            mysqlCommand.ExecutenonQuery()                            PopulateDataGrid()
                        Next
                    End If
                    MsgBox("New BIO Entry Successfully save",   MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "SUCCESSFULL")
                    txtAddBIO.Clear()
                Catch ex As Exception
                    MessageBox.Show(ex.ToString)
                End Try

            End If
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.