日期:2014-05-17  浏览次数:20496 次

从索引 0 处开始,初始化字符串的格式不符合规范。 急!坐等答案
“/Web_UI”应用程序中的服务器错误。
--------------------------------------------

从索引 0 处开始,初始化字符串的格式不符合规范。 
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.ArgumentException: 从索引 0 处开始,初始化字符串的格式不符合规范。

源错误: 


行 122: {
行 123: string sqlstr = "select * from T_Theater";
行 124: sqlcon = new SqlConnection(strCon);
行 125: SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
行 126: DataSet myds = new DataSet();
 
----------------------------------------------------
下面是代码
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;

public partial class _Default : System.Web.UI.Page
{
  SqlConnection sqlcon;
  SqlCommand sqlcom;
  string strCon = "MyOfficeConnectionString";
  // private static string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("/GuangDong/App_Data/#HS.mdb");


  protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  bind();
  }

  }
  protected void Unnamed1_Click(object sender, EventArgs e)
  {
  if (Fileupload1.HasFile)
  {
  //获取文件路径
  string path = Fileupload1.PostedFile.FileName;
  //获取文件名
  string FileName = Fileupload1.FileName;
  //根据文件结尾名判断文件格式
  if (FileName.ToLower().Substring(FileName.Length - 3) != "xls" && FileName.ToLower().Substring(FileName.Length - 4) != "xlsx")
  {
  Response.Write("<script type='text/JavaScript'>alert('请选择Excel文件!')</script>");
  return;
  }
  //获取Excel的数据datatable
  DataTable dt = GetTable(path, FileName);

  using (SqlConnection conn = new SqlConnection("server=.;database=Test;uid=sa;pwd=12345678;"))
  {
  conn.Open();
  SqlTransaction sqlTransaction = conn.BeginTransaction();
  // 将事务应用于Command  
  SqlCommand sqlCommand = new SqlCommand();
  sqlCommand.Connection = conn;
  sqlCommand.Transaction = sqlTransaction;
  try
  {
  foreach (DataRow row in dt.Rows)
  {
  string Theater = row["影院编号"].ToString();
  string TheaterName = row["影院名称(艺恩)"].ToString();
  string MonthBoxOffice = row["月票房"].ToString();
  string Nationalproportionof = row["全国占比(百分比显示)"].ToString();
  sqlCommand.CommandText = string.Format("insert into T_Theater([Theater],TheaterName,MonthBoxOffice,Nationalproportionof) values('{0}','{1}','{2}','{3}')", Theater, TheaterName, MonthBoxOffice, Nationalproportionof);//sql数据库
  sqlCommand.ExecuteNonQuery();
  }