如何在此代码中修复MYSQL致命错误?请帮助!!! [英] How to fix MYSQL fatal error in this code?PLEASE HELP!!!

查看:84
本文介绍了如何在此代码中修复MYSQL致命错误?请帮助!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用VB.NET在我的数据库中加载文本文件的批量记录,但我遇到了致命的错误。

这是我的代码:



I am trying to load bulk records of text files in my database using VB.NET and I run into a fatal error.
HERE'S MY CODE:

Public Sub LoadStudent(ByVal filepath As String)

Dim sql As String

sql =  "load data infile local '" & filepath & "' into table student_academic_table fields terminated by '\t' lines terminated by '\r\n' (@col1, @col2, @col3, @col4, @col5, @col6, @col7, @col8, @col9, @col10, @col11, @col12, @col13) set StudentIDNumber = @col1, LastName = @col2, FirstName = @col3, MiddleName = @col4, Course = @col5, _Year = @col6, Gender = @col7, OfferCode = @col8, SubjectName = @col9, SubjectDescription = @col10, MidtermGrade = @col11, FinalGrade = @col12, Units = @col13, TermCode = 0;"


SC.LoadData(sql)

End Sub



这是SC.LoadData(sql)的代码:



公共函数LoadData(ByVal sql As String)As Long




Here's the code for SC.LoadData(sql):

Public Function LoadData(ByVal sql As String) As Long

If sql.Trim.ToLower.StartsWith("load") Then
           Try
               Connect()
               cmd.CommandText = sql
               cmd.Connection = con
               Return cmd.ExecuteNonQuery()
               Disconnect()
           Catch ex As MySqlException
               Console.Write(ex.Message)
               MessageBox.Show(ex.Message)
           End Try
       End If
       Return 0

   End Function





我把它作为一个子程序,以便我可以将它用于其他功能,但它不会继续执行我希望它执行的esired函数,而不是在数据库中抛出致命错误异常。我尝试直接在我的MySql查询浏览器中执行它并执行它。但是在我的VB.NET应用程序中它发出致命错误,我已经在谷歌和其他论坛中查找相关文章或主题,但我找不到任何答案。我猜他的版本兼容性,我不知道如何解决这些问题。请帮助。



I made it as a sub so that I can use it to other functions, but it doesn't carry on the desired function that I want it to do, instead it throws a fatal error exception in the database. I tried executing it directly in my MySql Query Browser and it executed. But in my VB.NET application it fires a fatal error, I've already looked up in google and other forums for related articles or topics but I couldn't find any answer. My guess its version compatibility and I have no idea how to fix these kind of problems. PLEASE HELP.

推荐答案

在没有看到所有相关代码和错误详情的情况下,我会说你在中有潜在问题filepath 变量。



例如,如果您从C驱动器中选择一个文件并将文件名与路径一起传递,并且数据库位于另一台计算机上,则它不会查看您指定的路径中的文件。即使它位于同一台计算机上,数据库也可以访问您指定的目录。
Without seeing all of the relevant code and the error details, I'd say that you have a potential problem in the filepath variable.

For example if you select a file from your C-drive and pass the file name along with path and the database is located on a separate computer, it doesn't see the file in the path you have specified. Even if it resides on the same computer, does the database have access to the directory you have specified.


这篇关于如何在此代码中修复MYSQL致命错误?请帮助!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆