How can I save my documents to database sql server and open it.
I am using the control RichTextEditorRibbonBar
I want armagenar all information in the database and access starting from the database as well.
I want save all information (Doc,Richt,PDF) in the database and access starting from the database as well.
and export to my computer when necessary
I can not edit the elements "RibbonBar" to Portuguese
I can not also see the code to change to my taste
automatically configures and not the possibility of choice
Try--------------------------------------------SAVE-------------------------------------------------
rtbDoc.SaveFile("temp.rtf")
stream = New FileStream("temp.rtf", FileMode.Open, FileAccess.Read)
Dim size As Integer = Convert.ToInt32(stream.Length)
Dim rtf As [Byte]() = New [Byte](size - 1) {}
stream.Read(rtf, 0, size)
Dim paramRTF As New SqlParameter("@Documento", SqlDbType.VarBinary, rtf.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, rtf)
' cmd.Parameters.Add(paramRTF)
Using connection As New SqlClient.SqlConnection(Ligarservidor)
connection.Close()
Dim SQL As String = "INSERT INTO doc (ID,Processo,data,tipo,Documento) VALUES (@ID,@Processo,@data,@Tipo,@Documento);"
Dim command As New SqlCommand(SQL, connection)
command.Parameters.AddWithValue("@ID", SqlDbType.NVarChar).Value = "1"
command.Parameters.AddWithValue("@Processo", SqlDbType.NVarChar).Value = "W"
command.Parameters.AddWithValue("@Data", SqlDbType.NVarChar).Value = "W"
command.Parameters.AddWithValue("@Tipo", SqlDbType.NVarChar).Value = "W"
command.Parameters.Add(paramRTF)
connection.Open()
command.ExecuteNonQuery()
MessageBox.Show("Informação registada!...", "Info")
End Using
Catch ex As Exception
Finally
If stream IsNot Nothing Then
stream.Close()
End If
End Try
-------------------------------------------------------------READ------------------------------------------------------------------
Dim cn As SqlConnection = Nothing
Dim cmd As SqlCommand = Nothing
Dim reader As SqlDataReader = Nothing
Try
cn = New SqlConnection(Ligarservidor)
cn.Open()
cmd = New SqlCommand("SELECT documento FROM doc WHERE ID=1", cn)
reader = cmd.ExecuteReader()
reader.Read()
If reader.HasRows Then
If Not reader.IsDBNull(0) Then
Dim rtf As [Byte]() = New [Byte](Convert.ToInt32((reader.GetBytes(0, 0, Nothing, 0, Int32.MaxValue))) - 1) {}
Dim bytesReceived As Long = reader.GetBytes(0, 0, rtf, 0, rtf.Length)
Dim encoding As New ASCIIEncoding()
rtbDoc.Rtf = encoding.GetString(rtf, 0, Convert.ToInt32(bytesReceived))
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If reader IsNot Nothing Then
reader.Close()
End If
If cn IsNot Nothing Then
cn.Close()
End If
End Try
I am using the control RichTextEditorRibbonBar
I want armagenar all information in the database and access starting from the database as well.
I want save all information (Doc,Richt,PDF) in the database and access starting from the database as well.
and export to my computer when necessary
I can not edit the elements "RibbonBar" to Portuguese
I can not also see the code to change to my taste
automatically configures and not the possibility of choice
Try--------------------------------------------SAVE-------------------------------------------------
rtbDoc.SaveFile("temp.rtf")
stream = New FileStream("temp.rtf", FileMode.Open, FileAccess.Read)
Dim size As Integer = Convert.ToInt32(stream.Length)
Dim rtf As [Byte]() = New [Byte](size - 1) {}
stream.Read(rtf, 0, size)
Dim paramRTF As New SqlParameter("@Documento", SqlDbType.VarBinary, rtf.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, rtf)
' cmd.Parameters.Add(paramRTF)
Using connection As New SqlClient.SqlConnection(Ligarservidor)
connection.Close()
Dim SQL As String = "INSERT INTO doc (ID,Processo,data,tipo,Documento) VALUES (@ID,@Processo,@data,@Tipo,@Documento);"
Dim command As New SqlCommand(SQL, connection)
command.Parameters.AddWithValue("@ID", SqlDbType.NVarChar).Value = "1"
command.Parameters.AddWithValue("@Processo", SqlDbType.NVarChar).Value = "W"
command.Parameters.AddWithValue("@Data", SqlDbType.NVarChar).Value = "W"
command.Parameters.AddWithValue("@Tipo", SqlDbType.NVarChar).Value = "W"
command.Parameters.Add(paramRTF)
connection.Open()
command.ExecuteNonQuery()
MessageBox.Show("Informação registada!...", "Info")
End Using
Catch ex As Exception
Finally
If stream IsNot Nothing Then
stream.Close()
End If
End Try
-------------------------------------------------------------READ------------------------------------------------------------------
Dim cn As SqlConnection = Nothing
Dim cmd As SqlCommand = Nothing
Dim reader As SqlDataReader = Nothing
Try
cn = New SqlConnection(Ligarservidor)
cn.Open()
cmd = New SqlCommand("SELECT documento FROM doc WHERE ID=1", cn)
reader = cmd.ExecuteReader()
reader.Read()
If reader.HasRows Then
If Not reader.IsDBNull(0) Then
Dim rtf As [Byte]() = New [Byte](Convert.ToInt32((reader.GetBytes(0, 0, Nothing, 0, Int32.MaxValue))) - 1) {}
Dim bytesReceived As Long = reader.GetBytes(0, 0, rtf, 0, rtf.Length)
Dim encoding As New ASCIIEncoding()
rtbDoc.Rtf = encoding.GetString(rtf, 0, Convert.ToInt32(bytesReceived))
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If reader IsNot Nothing Then
reader.Close()
End If
If cn IsNot Nothing Then
cn.Close()
End If
End Try