我这样为什么获取不到呢
SqlConnection myConn = new SqlConnection("Data Source=.;Initial Catalog=Weibo;User ID=saassword='sinorich';");
SheetView _sv;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//绑定数据
showdata();
//设置行为只读
_sv = FpSpread1.Sheets[0];
_sv.AddColumns(6, 1);
_sv.Columns[6].Label = "老师姓名";
}
FarPoint.Web.Spread.DateTimeCellType datecell = new FarPoint.Web.Spread.DateTimeCellType();
//datecell.MaximumValue = new System.DateTime(2050, 12, 31, 0, 0, 0, 0);
//datecell.MinimumValue = new System.DateTime(2001, 1, 1, 0, 0, 0, 0);
//this.FpSpread1.ActiveSheetView.Columns[1, 2].CellType = datecell;
//FpSpread1.ActiveSheetView.Protect = true;
FpSpread1.ActiveSheetView.Columns[0, 5].Locked = true;
}
/// <summary>
/// 绑定数据
/// </summary>
public void showdata()
{
string strCom = "select a.S#, a.Sname, a.Sage, a.Ssex,b.name,b.score from Student as a join SC as b on a.S#=b.S# where b.name!='' ";
//创建一个 DataSet对象
DataSet myDataSet = new DataSet();
myConn.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(strCom, myConn);
myCommand.Fill(myDataSet);
this.FpSpread1.DataSource = myDataSet;
myConn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
var cmd = new SqlCommand();
myConn.Open();
cmd.Connection = myConn;
_sv = FpSpread1.Sheets[0];
var colcount = _sv.ColumnCount;
var currow = _sv.ActiveRow;//当前活跃的行索引;
string sqlInsert = "insert into Teacher (Tname,S#) values(@Tname,@S#)";
if (FpSpread1.ActiveSheetView.Rows.Count > 0)
{
for (int i = 0; i < FpSpread1.ActiveSheetView.Rows.Count; i++)
{
for (var j = colcount-1; j >= 0; j--)
{
SqlParameter[] parameters = new SqlParameter[2]
{
new SqlParameter("@Tname", SqlDbType.VarChar, 40),
new SqlParameter("@S#", SqlDbType.VarChar, 40),
};
parameters[0] = new SqlParameter("@Tname", _sv.Cells[currow, j].Value);
parameters[1] = new SqlParameter("@S#", _sv.Cells[currow, 0].Value);
cmd.Parameters.Add(parameters);
break;
}
cmd.CommandText = sqlInsert.ToString();
var count = 0;
try
{
count = cmd.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
if (count >= 1)
{
Response.Write("<script>alert('添加成功');</script>");
}
}
}
myConn.Close();
}
} |