Click here to Skip to main content
15,895,011 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: help with playing a dvd Pin
Its_Me_Lenny9-Jun-07 1:08
Its_Me_Lenny9-Jun-07 1:08 
QuestionAppend an Image to Every Printed Docmumet? Pin
CJ1998-Jun-07 10:59
CJ1998-Jun-07 10:59 
AnswerRe: Append an Image to Every Printed Docmumet? Pin
Dave Kreskowiak8-Jun-07 14:19
mveDave Kreskowiak8-Jun-07 14:19 
QuestionVS.Net Pro & Crystal Reports... Pin
CCG38-Jun-07 8:56
CCG38-Jun-07 8:56 
AnswerRe: VS.Net Pro & Crystal Reports... Pin
Dave Kreskowiak8-Jun-07 9:56
mveDave Kreskowiak8-Jun-07 9:56 
GeneralRe: VS.Net Pro & Crystal Reports... Pin
CCG38-Jun-07 10:01
CCG38-Jun-07 10:01 
GeneralRe: VS.Net Pro & Crystal Reports... Pin
Dave Kreskowiak8-Jun-07 10:25
mveDave Kreskowiak8-Jun-07 10:25 
QuestionInvalid cast from System.String to System.Byte[ ] [modified] Pin
ASPnoob8-Jun-07 6:47
ASPnoob8-Jun-07 6:47 
Hi, I get the following error message when I run my application in the browser.

"Invalid cast from System.String to System.Byte[ ]"

I have changed cmdInsert.Parameters.Add("@docContent",OdbcType.Text) to cmdInsert.Parameters. Add("@docContent",OdbcType.Binary) like someone had suggested, but it still does not work. I have checked other variables for type mismatch but didn't find any. If you see anything at all wrong with my code please point it out. I would really be grateful if you can show me what is causing VS2003 to throw the exception. Thank you in advance for your help. The following are my code and database to help you better understand my situation.

---------------------------------------------------------------------------------------------    
 |  Field           |   Type          |   Null    |   Key     |default                   |   Extra             |
--------------------------------------------------------------------------------------------------
 | docID           | int(11)          | NO       |   PRI     | NULL                     | AUTO_INCREMENT  |
 |

 | docTitle        | varchar(30)     | NO       |           | NULL                      |                      |
 | 
 
 | docContent    | MediumBlob      | NO       |          | NULL                        |                      |
 |

 | docDate        | timestamp       | NO       |           | CURRENT_TIMESTAMP   |                      |
 |

 | docType        | varchar(15)     | NO       |           | NULL                      |                     |
----------------------------------------------------------------------------------------------------
Imports System.IO
Imports System.Data.Odbc
Public Class Upload
    Inherits System.Web.UI.Page

 Private Sub Submit1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.Click
        Dim strFileExtension As String
        Dim StrFileType As String
        Dim intFileLen As Integer
        Dim objStream As Stream
        Dim strInsert As String
        Dim myConnection As OdbcConnection
        Dim cmdInsert As OdbcCommand


        If Not IsNothing(txtFileContents.PostedFile) Then
            'Determines File Type
            strFileExtension = Right(txtFileContents.PostedFile.FileName, 4)
            Select Case strFileExtension.ToLower
                Case ".doc"
                    StrFileType = "doc"
                Case ".ppt"
                    StrFileType = "ppt"
                Case ".htm"
                    StrFileType = "htm"
                Case ".html"
                    StrFileType = "html"
                Case ".txt"
                    StrFileType = "txt"
                Case Else
                    StrFileType = "jpg"
            End Select
            'Grab the content of uploaded file
            intFileLen = txtFileContents.PostedFile.ContentLength
            Dim arrFile(intFileLen) As Byte
            objStream = txtFileContents.PostedFile.InputStream
            objStream.Read(arrFile, 0, intFileLen)


            'Add UpLoaded file to a database
            myConnection = New OdbcConnection("Provider=MySQLProv; Data Source=Data;User Id=myIDassword=myPWD")
            strInsert = "INSERT into QUsers (docTitle,docContent,docDate,docType) values (?,?,?,?,?)"
            cmdInsert = new odbcCommand(strInsert,myConnection)
            
            cmdInsert.Parameters.Add("@docID",OdbcType.int,30)           
            cmdInsert.Parameters["@docID"].Values =""

            cmdInsert.Parameters.Add("@docDate", OdbcType.TimeStame,14)             
            cmdInsert.Parameters["@docDate"].Values = DateTime.Now.ToShortDateString()

            cmdInsert.Parameters.Add("@docTitle", OdbcType.Varchar,30  )
            cmdInsert.Parameters["@docTitle"].Values = txtFileTitle.Text       
            
            cmdInsert.Parameters.Add("@docType", OdbcType.Varchar,30)
            cmdInsert.Parameters["@docType"].Values =StrFileType

            cmdInsert.Parameters.Add("@docContent",OdbcType.Binary)           
            cmdInsert.Parameters["@docContent"].Values =arrFile
            
            myConnection.Open()
            cmdInsert.ExecuteNonQuery()
            myConnection.Close()
        End If









-- modified at 15:16 Friday 8th June, 2007
AnswerRe: Invalid cast from System.String to System.Byte[ ] Pin
Dave Kreskowiak8-Jun-07 8:04
mveDave Kreskowiak8-Jun-07 8:04 
GeneralRe: Invalid cast from System.String to System.Byte[ ] Pin
ASPnoob8-Jun-07 9:01
ASPnoob8-Jun-07 9:01 
GeneralRe: Invalid cast from System.String to System.Byte[ ] Pin
Dave Kreskowiak8-Jun-07 9:45
mveDave Kreskowiak8-Jun-07 9:45 
GeneralRe: Invalid cast from System.String to System.Byte[ ] Pin
ASPnoob8-Jun-07 13:51
ASPnoob8-Jun-07 13:51 
GeneralRe: Invalid cast from System.String to System.Byte[ ] Pin
Dave Kreskowiak8-Jun-07 14:17
mveDave Kreskowiak8-Jun-07 14:17 
Questioninsert and select query in a single stored procedure Pin
Sonia Gupta8-Jun-07 2:49
Sonia Gupta8-Jun-07 2:49 
AnswerRe: insert and select query in a single stored procedure Pin
reegan418-Jun-07 3:00
reegan418-Jun-07 3:00 
GeneralRe: insert and select query in a single stored procedure Pin
Steven J Jowett8-Jun-07 3:23
Steven J Jowett8-Jun-07 3:23 
GeneralRe: insert and select query in a single stored procedure Pin
reegan418-Jun-07 3:30
reegan418-Jun-07 3:30 
GeneralRe: insert and select query in a single stored procedure Pin
Steven J Jowett8-Jun-07 3:39
Steven J Jowett8-Jun-07 3:39 
GeneralRe: insert and select query in a single stored procedure Pin
reegan418-Jun-07 3:42
reegan418-Jun-07 3:42 
AnswerRe: insert and select query in a single stored procedure Pin
Marcus J. Smith8-Jun-07 3:43
professionalMarcus J. Smith8-Jun-07 3:43 
AnswerRe: insert and select query in a single stored procedure Pin
Guffa8-Jun-07 4:30
Guffa8-Jun-07 4:30 
QuestionReports with Word Pin
reegan418-Jun-07 2:47
reegan418-Jun-07 2:47 
Questionhow can i create a user group,user in active directory using vb 6.0 Pin
koolprasad20038-Jun-07 2:41
professionalkoolprasad20038-Jun-07 2:41 
AnswerRe: how can i create a user group,user in active directory using vb 6.0 Pin
Dave Kreskowiak8-Jun-07 4:05
mveDave Kreskowiak8-Jun-07 4:05 
Questionstored procedure eror in vb.net 2005 [modified] Pin
Sonia Gupta8-Jun-07 2:18
Sonia Gupta8-Jun-07 2:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.