Solved

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

Posted on 2004-08-17
6
248 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

821 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