Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-08-17
6
Medium Priority
?
268 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

604 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