Solved

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

Posted on 2004-08-17
6
240 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
Comment Utility
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
Comment Utility
could you be more specific? Thanks.
0
 
LVL 3

Expert Comment

by:Scoobyed
Comment Utility
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:patrickkenney
Comment Utility
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
Comment Utility
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
Comment Utility
Worked like a charm!! Thanks!!!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

16 Experts available now in Live!

Get 1:1 Help Now