?
Solved

Need help with notes field for database application - VB.NET and SQL 2000

Posted on 2004-08-17
6
Medium Priority
?
262 Views
Last Modified: 2010-04-23
I need to be able to insert notes in a database application using VB.NET front end and SQL 2000 as the database backend. Here is how I would like to be able to insert notes.

I have a richtextbox, textbox and button on a form. I would like to be able to enter text into the textbox and have it add a new line to the richtextbox when I click on the button. I know this can be done, but I'm pulling a blank on getting the notes to show up in the richtextbox line by line and then be update in the varbinary notes field in sql. Please help! Thanks in advance!!!
0
Comment
Question by:patrickkenney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:Jigit
ID: 11829920
Perform the following actions in OnClick event handler of your button
1. Open connection to the database
2. Create INSERT query with appropriate parameters: from the richtextbox and the textbox
3. Execute the above query
4. Close connection

HTH,
Jigit
0
 

Author Comment

by:patrickkenney
ID: 11835524
could you be more specific? Thanks.
0
 
LVL 3

Expert Comment

by:Scoobyed
ID: 11839968
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:patrickkenney
ID: 11842029
That has nothing to do with what I'm asking. Please reread my original question. Thanks!
0
 
LVL 3

Accepted Solution

by:
Scoobyed earned 2000 total points
ID: 11850515
it was load / save blob (streams etc.), from that, I worked this out for the db side, as for the line by line into a rich text box, try

            Me.RichTextBox1.Text = Me.RichTextBox1.Text & Me.TextBox1.Text & ControlChars.CrLf

db load / save

            ' load data from sql dataset
            Try
                  Dim cnn As SqlClient.SqlConnection
                  Dim strConn As String = "Integrated Security=true;initial catalog=Northwind"
                  Dim sql As String = "SELECT * FROM Employees WHERE EmployeeID=1"
                  cnn = New SqlClient.SqlConnection(strConn)
                  cnn.Open()
                  Dim cmd As SqlClient.SqlCommand = cnn.CreateCommand

                  cmd.CommandText = sql
                  cmd.CommandType = CommandType.Text
                  Dim ds As DataSet = New DataSet
                  Dim da As New SqlClient.SqlDataAdapter
                  da.SelectCommand = New SqlClient.SqlCommand(sql, cnn)
                  da.Fill(ds)

                  Dim stream As New IO.FileStream("c:\temp2.rtf", IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
                  Dim encoding As New System.Text.ASCIIEncoding
                  Dim rtf As [Byte]() = encoding.GetBytes(ds.Tables(0).Rows(0).Item("Notes").ToString)
                  stream.Write(rtf, 0, rtf.Length)
                  stream.Close()
                  Me.RichTextBox1.LoadFile("c:\temp2.rtf")

                  cnn.Close()
            Catch ex As Exception
                  MessageBox.Show(ex.Message)
            End Try



            ' save data to sql using dataset
            Try
                  Dim connect As New SqlClient.SqlConnection("Initial Catalog = Northwind;Data Source =(local);User ID=sa;password=;Connect Timeout = 20")

                  connect.Open()

                  Dim command As String = "SELECT * from employees WHERE EmployeeID=1"
                  Dim ds As New DataSet

                  Dim adaptor As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(command, connect)
                  Dim cmdBuilder As SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder(adaptor)

                  adaptor.Fill(ds)

                  Me.RichTextBox1.SaveFile("c:\temp.rtf")
                  Dim fs As New IO.FileStream("c:\temp.rtf", IO.FileMode.Open, IO.FileAccess.Read)
                  Dim rtf(255) As Byte
                  fs.Read(rtf, 0, CType(fs.Length, Integer))
                  Dim i As Integer
                  Dim encoding As New System.Text.ASCIIEncoding
                  ds.Tables(0).Rows(0).Item("Notes") = encoding.GetString(rtf, 0, Convert.ToInt32(fs.Length))
                  fs.Close()

                  adaptor.UpdateCommand = cmdBuilder.GetUpdateCommand()
                  Debug.WriteLine(cmdBuilder.GetUpdateCommand.CommandText)

                  Dim intUpdated As Integer
                  intUpdated = adaptor.Update(ds.Tables(0))

                  MessageBox.Show("Updated: " & intUpdated.ToString)

            Catch ex As Exception
                  MessageBox.Show(ex.Message)
            End Try
0
 

Author Comment

by:patrickkenney
ID: 11851424
Worked like a charm!! Thanks!!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question