Error: The method or operation is not implemented. plz solve

Jun 13 2015 4:03 AM
hi i have a problem that is
when i am inserting a .csv file into database then a error message are occur . this error massage is
Error: The method or operation is not implemented.
i am using sql server database and visual stdio. and i am using asp.net and c#.
my code are bellow
that is my design page code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="file25.aspx.cs" Inherits="uploadfile25.file25" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body bgcolor="Silver">
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
Select File
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" ToolTip="Select Only Excel File" />
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Upload" onclick="Button1_Click" />
</td>
<td>
<asp:Button ID="Button2" runat="server" Text="View Files"
onclick="Button2_Click" />
</td>
</tr>
</table>
<table><tr><td><p><asp:Label ID="Label2" runat="server" Text="label"></asp:Label> </p></td></tr></table>
<asp:GridView ID="GridView1" runat="server" Caption="Excel Files "
CaptionAlign="Top" HorizontalAlign="Justify"
DataKeyNames="id" onselectedindexchanged="GridView1_SelectedIndexChanged"
ToolTip="Excel FIle DownLoad Tool" CellPadding="4" ForeColor="#333333"
GridLines="None">
<RowStyle BackColor="#E3EAEB" />
<Columns>
<asp:CommandField ShowSelectButton="True" SelectText="Download" ControlStyle-ForeColor="Blue"/>
</Columns>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="Gray" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</form>
</body>
</html>
and
this is my .cs page code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Drawing;
using System.Data.OleDb;
namespace uploadfile25
{
public partial class file25 : System.Web.UI.Page
{
public SqlCommand com { get; set; }public string query { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label2.Visible = true;
string filePath = FileUpload1.PostedFile.FileName; // getting the file path of uploaded file
string filename1 = Path.GetFileName(filePath); // getting the file name of uploaded file
string ext = Path.GetExtension(filename1); // getting the file extension of uploaded file
string type = String.Empty;
if (!FileUpload1.HasFile)
{
Label2.Text = "Please Select File"; //if file uploader has no file selected
}
else
if (FileUpload1.HasFile)
{
try
{
switch (ext) // this switch code validate the files which allow to upload only excel file you can change it for any file
{
case ".xls":
type = "application/vnd.ms-excel";
break;
case ".xlsx":
type = "application/vnd.ms-excel";
break;
case ".csv":
type = "application/vnd.ms-excle";
break;
}
if (type != String.Empty)
{
connection();
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs); //reads the binary files
Byte[] bytes = br.ReadBytes((Int32)fs.Length); //counting the file length into bytes
query = "insert into vicidialdemo(phone_number,title,first_name,middle_initial,last_name,address,city,state,province,postal_code,country_code,gender,date_of_birth,alt_phone,email)"
+ " values (@phone_number, @title, @first_name, @middle_initial, @last_name, @address, @city, @state, @province, @postal_code, @country_code, @gender, @date_of_birth, @alt_phone, @email)"; //insert query
com = new SqlCommand(query, con);
com.Parameters.Add("@phone_number", SqlDbType.VarChar).Value = phone_number;
com.Parameters.Add("@title", SqlDbType.VarChar).Value = title;
com.Parameters.Add("@first_name", SqlDbType.Binary).Value = first_name;
com.Parameters.Add("@middle_initial", SqlDbType.Binary).Value = middle_initial;
com.Parameters.Add("@last_name", SqlDbType.Binary).Value = last_name;
com.Parameters.Add("@address", SqlDbType.Binary).Value = addres;
com.Parameters.Add("@city", SqlDbType.Binary).Value = city;
com.Parameters.Add("@state", SqlDbType.Binary).Value = state;
com.Parameters.Add("@province", SqlDbType.Binary).Value = province;
com.Parameters.Add("@postal_code", SqlDbType.Binary).Value = postal_code;
com.Parameters.Add("@country_code", SqlDbType.Binary).Value = country_code;
com.Parameters.Add("@gender", SqlDbType.Binary).Value = gender;
com.Parameters.Add("@date_of_birth", SqlDbType.Binary).Value = date_of_birth;
com.Parameters.Add("@alt_phone", SqlDbType.Binary).Value = alt_phone;
com.Parameters.Add("@email", SqlDbType.Binary).Value = email;
com.ExecuteNonQuery();
Label2.ForeColor = System.Drawing.Color.Green;
Label2.Text = "File Uploaded Successfully";
}
else
{
Label2.ForeColor = System.Drawing.Color.Red;
Label2.Text = "Select Only Excel File having extension .xlsx or .xls or .csv "; // if file is other than speified extension
}
}
catch (Exception ex)
{
Label2.Text = "Error: " + ex.Message.ToString();
}
}
}
// private void connection()
// {
// throw new NotImplementedException();
// }
protected void Button2_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
connection();
query = "Select *from vicidialdemo";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds, "vicidialdemo");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
con.Close();
}
private void connection()
{
throw new NotImplementedException();
}
// private void connection()
//{
// throw new NotImplementedException();
// }
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Data Source=ANIRUDDHA-PC;Initial Catalog=dddd;Integrated Security=True"].ToString()))
{
con.Open();
SqlCommand cmd = new SqlCommand("select Name,type,data from vicidialdemo where ID=@ID", con);
cmd.Parameters.AddWithValue("id", GridView1.SelectedRow.Cells[1].Text);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = dr["type"].ToString();
// to open file prompt Box open or Save file
Response.AddHeader("content-disposition", "attachment;filename=" + dr["Name"].ToString());
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite((byte[])dr["data"]);
Response.End();
}
}
}
public SqlConnection con { get; set; }
public object phone_number { get; set; }
public object title { get; set; }
public object first_name { get; set; }
public object middle_initial { get; set; }
public object last_name { get; set; }
public object address { get; set; }
public object addres { get; set; }
public object city { get; set; }
public object state { get; set; }
public object province { get; set; }
public object postal_code { get; set; }
public object country_code { get; set; }
public object gender { get; set; }
public object date_of_birth { get; set; }
public object alt_phone { get; set; }
public object email { get; set; }
}
}
.
please help me.
thanks

Answers (15)