Solved

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

Posted on 2004-08-17
6
242 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now