可不可一帮我把下面的代码转成mvc模式(愿意在线等到三点)
这是一个实现把excel数据导入到数据库的代码,对mvc不是很熟悉,也是一个菜鸟请求您的帮助
public partial class TEST_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//获取文件路径
string filePath = this.FileUpload1.PostedFile.FileName;
if (filePath != "")
{
if (filePath.Contains("xls"))//判断文件是否存在
{
InputExcel(filePath);
}
else
{
Response.Write("请检查您选择的文件是否为Excel文件!谢谢!");
}
}
else
{
Response.Write("请先选择导入文件后,再执行导入!谢谢!");
}
}
private void InputExcel(string pPath)
{
string conn = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" + pPath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'";
OleDbConnection oleCon = new OleDbConnection(conn);
oleCon.Open();
string Sql = "select * from [Sheet1$]";
OleDbDataAdapter mycommand = new OleDbDataAdapter(Sql, oleCon);
DataSet ds = new DataSet();
mycommand.Fill(ds, "[Sheet1$]");
oleCon.Close();
int count = ds.Tables["[Sheet1$]"].Rows.Count;
for (int i = 0; i < count; i++)
{
string tRealName, tSex, tInClass, tQuestion, tAnswer;
tRealName = ds.Tables["[Sheet1$]"].Rows[i]["姓名"].ToString().Trim();