尝试读取结果集时遇到致命错误。 [英] Fatal error encountered attempting to read the resultset.

查看:1146
本文介绍了尝试读取结果集时遇到致命错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在csv文件上传期间出现错误。在这个地方myCUpload.ExecuteNonQuery();显示尝试读取结果集时遇到的致命错误。



代码如下:



Error show during csv file uploading.At this place myCUpload.ExecuteNonQuery(); show the Fatal error encountered attempting to read the resultset.

code is given below..

string path = FileUpload1.PostedFile.FileName;
            string ext = Path.GetExtension(path);
            string contenttype = string.Empty;
            if (!FileUpload1.HasFile)
            {

                ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Please select a file')</script>");  //if file uploader has no file selected

            }
            else if (FileUpload1.HasFile)
            {
                try
                {
                    switch (ext)
                    {
                        case ".csv":

                            contenttype = "application/vnd.ms-excel";

                            break;
                    }
                    string year = ddlyear.SelectedItem.ToString();
                    string month = ddlmonth.SelectedItem.ToString();
                    MySqlConnection exclecon = new MySqlConnection("Server=Localhost;DataBase=password1;user=root;password=nectar");
                    string insquery = "INSERT INTO sla (month, year, contenttype) VALUES(@month, @year, @contenttype)";
                    string uploadQry = "LOAD DATA LOCAL  INFILE '" + path + "' INTO TABLE sla1 FIELDS TERMINATED  BY ','  LINES TERMINATED BY '\\n' IGNORE 1 LINES ";
                    MySqlCommand mycom = new MySqlCommand(insquery, exclecon);
                    mycom.Parameters.AddWithValue("@month", month);
                    mycom.Parameters.AddWithValue("@year", year);
                    mycom.Parameters.Add("@contenttype", MySqlDbType.VarChar).Value = contenttype;
                    MySqlCommand myCUpload = new MySqlCommand(uploadQry, exclecon);
                    exclecon.Open();
                    mycom.ExecuteNonQuery();
                    myCUpload.ExecuteNonQuery();
                    ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('File uploaded Successfully ')</script>");
                    con.Close();

                }

                catch (Exception ex)
                {
                    Label4.Text = "Error: " + ex.Message.ToString();

                }
            }
        }
    }

推荐答案

每次ExecuteNonQuery(),你必须编写Dispose()。
After each ExecuteNonQuery(), you must write Dispose().


这篇关于尝试读取结果集时遇到致命错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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