清空照片你就找一个通用照片提前存到数据库上,每次清空的时候就把这个照片的url连上,显示这个照片!。。。
protected void Button2_Click(object sender, EventArgs e)//上传照片
{
string strConn = "Data Source=;DataBase=数据库名;Uid=sa;Pwd=sa";
if (FileUpload1HasFile == false)//HasFile用来检查FileUpload是否有指定文件
{
ResponseWrite("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 10 Transitional//EN' '>#region 连接Excel 读取Excel数据 并返回DataSet数据集合
/// <summary>
/// 连接Excel 读取Excel数据 并返回DataSet数据集合
/// </summary>
/// <param name="filepath">Excel服务器路径</param>
/// <param name="tableName">Excel表名称</param>
/// <returns></returns>
public static SystemDataDataSet ExcelSqlConnection(string filepath, string tableName)
{
string strCon = "Provider=MicrosoftJetOLEDB40;Data Source=" + filepath + ";Extended Properties='Excel 80;HDR=YES;IMEX=1'";
OleDbConnection ExcelConn = new OleDbConnection(strCon);
try
{
string strCom = stringFormat("SELECT FROM [Sheet1$]");
ExcelConnOpen();
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, ExcelConn);
DataSet ds = new DataSet();
myCommandFill(ds, "[" + tableName + "$]");
ExcelConnClose();
return ds;
}
catch
{
ExcelConnClose();
return null;
}
}
#endregion
#region 导入的execl
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection cn = new BSqlDataProvider()GetSqlConnection();
cnOpen();
if (FileUpload1HasFile == false)//HasFile用来检查FileUpload是否有指定文件
{
ResponseWrite("<script>alert('请您选择Excel文件')</script> ");
return;//当无文件时,返回
}
string IsXls = SystemIOPathGetExtension(FileUpload1FileName)ToString()ToLower();//SystemIOPathGetExtension获得文件的扩展名
if (IsXls != "xls")
{
ResponseWrite("<script>alert('只可以选择Excel文件')</script>");
return;//当选择的不是Excel文件时,返回
}
string filename = FileUpload1FileName; //获取Execle文件名 DateTime日期函数
string savePath = ServerMapPath(("~\\upfiles\\") + filename);//ServerMapPath 获得虚拟服务器相对路径
FileUpload1SaveAs(savePath); //SaveAs 将上传的文件内容保存在服务器上
DataSet ds = ExcelSqlConnection(savePath, filename); //调用自定义方法
DataRow[] dr = dsTables[0]Select(); //定义一个DataRow数组
int rowsnum = dsTables[0]RowsCount;
if (rowsnum == 0)
{
ResponseWrite("<script>alert('Excel表为空表,无数据!')</script>"); //当Excel表为空时,对用户进行提示
}
else
{
for (int i = 0; i < drLength; i++)
{
string spdm = dr[i]["商品代码"]ToString();//日期 excel列名
string jijie = dr[i]["季节"]ToString();
string boduan = dr[i]["波段"]ToString();
string s_chan = dr[i]["生产商"]ToString();
string f_shi = dr[i]["方式"]ToString();
string c_ku = dr[i]["仓库"]ToString();
string insertstr = "insert into AA_ANSD values('"+spdm+"','"+jijie+"','"+boduan+"','"+s_chan+"','"+f_shi+"','"+c_ku+"')";
SqlCommand cmd = new SqlCommand(insertstr, cn);
try
{
cmdExecuteNonQuery();
}
catch (MembershipCreateUserException ex) //捕捉异常
{
ResponseWrite("<script>alert('导入内容:" + exMessage + "')</script>");
}
}
ResponseWrite("<script>alert('Excle表导入成功!');location='CMT_EntryaspxCMD=0'</script>");
}
cnClose();
}
#endregion
快给分 啊
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)