Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何将文件上载到数据库_Mysql_Vb.net - Fatal编程技术网

Mysql 如何将文件上载到数据库

Mysql 如何将文件上载到数据库,mysql,vb.net,Mysql,Vb.net,好的,我正在尝试将所选文件的名称、类型、大小(以字节为单位)以及文件本身上传到数据库。到目前为止,除了将文件自己上传到数据库之外,我一切都进行得很顺利。因此,我的问题是如何将文件本身上载到数据库 这是我的代码,我已经有了 Dim s = My.Computer.FileSystem.GetFileInfo(OpenFileDialog1.FileName) MessageBox.Show("File Name:" & s.Name) MessageBox.Show

好的,我正在尝试将所选文件的名称、类型、大小(以字节为单位)以及文件本身上传到数据库。到目前为止,除了将文件自己上传到数据库之外,我一切都进行得很顺利。因此,我的问题是如何将文件本身上载到数据库

这是我的代码,我已经有了

    Dim s = My.Computer.FileSystem.GetFileInfo(OpenFileDialog1.FileName)
    MessageBox.Show("File Name:" & s.Name)
    MessageBox.Show("File Type:" & s.Extension)
    MessageBox.Show("File Size (Bytes):" & s.Length)
    Try

        Dim cmd As New MySqlCommand
        Dim insertStatment As String = "INSERT INTO upload (name, type, size) VALUES 
        (@name, @type, @size)"
        cmd = New MySqlCommand(insertStatment, db_con)
        cmd.Parameters.AddWithValue("@name", s.Name)
        cmd.Parameters.AddWithValue("@type", s.Extension)
        cmd.Parameters.AddWithValue("@size", s.Length)

        cmd.ExecuteNonQuery()
        MessageBox.Show("ok")
        db_con.Close()
           Catch ex As Exception
        MessageBox.Show("Something went wrong, please try again")
        db_con.Close()
       End Try

看看这个链接


这是我在一个月前遇到同样问题时使用的,它对我有效。它是用C#编写的,但是对于VB.NET来说,它是完全一样的,我相信将这里给出的C#代码翻译成VB.NET不会是一个问题

欢迎使用StackOverflow。没有必要在问题的标题中添加可以添加到标签中的信息。标签系统在这里工作得很好。谢谢。:-)(顺便提一下,这个问题问得很好。+1。)您确定要将文件本身上载到数据库吗?这背后有一些原因(特别是如果数据库被一些不受您控制的系统使用,您只需要遵守它,等等),但是您是否考虑过将文件单独存储在文件系统中的某个位置,并且只在数据库中存储路径?请参阅我的帖子,它对我有用,而不是在C#,这是PHP.oh,链接是用PHP编写的,不是用c编写的#