为了此问题,我再出30分!
解决方案 »
- 关于用HttpWebRequest下载文件的问题
- 求救xml读取的问题
- datagridview操作图片
- 如何编程进行IIS的相关设置啊?
- 定义一个方法怎么接收任意多个参数..?
- 用PrintDocument对象进行打印时怎样进行分页啊?(非常谢谢!)
- 如何读文本文件内容存入数据库中?
- 新手上路,求好书!推荐好书人人有分!
- 关于在 Visual C#.NET 嵌入 Visual C++ 6.0 代码的问题
- nean再进来看看
- installshield 8+.net制作安装文件后安装的问题(.net1.1)
- windows服务(system用户运行)中如何启动一个administrator的进程?
您会吗?若会,请指教!谢谢!
string file;
file=UploadFile.Value;
string qry="insert into testtable1 select * from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0','Data Source="+file+";User ID=Admin;Password=;Extended properties=Excel 8.0')...Sheet1$";
cnn.Open();
SqlCommand cmd=new SqlCommand(qry,cnn);
cmd.ExecuteNonQuery();
cnn.Close();
file=UploadFile.Value;//这是上传的文件路径
string strConn= "Provider=Microsoft.Jet.OleDb.4.0; data source='"+file+"';Extended Properties=Excel 8.0;";
OleDbConnection objConn=new OleDbConnection(strConn);
objConn.Open();
string strSql= "Select * From [sheet1$]";
OleDbDataAdapter sqlada=new OleDbDataAdapter(strSql, objConn);
DataSet data=new DataSet();
sqlada.Fill(data,"problem");
objConn.Close();
string strconn="server=(local);uid=sa;pwd=sa;database=test";
SqlConnection conn=new SqlConnection(strconn);
conn.Open();
String SqlCmd = "INSERT INTO testtable(编号,题型,基本类型) VALUES(@id,@type,@basetype)";
SqlCommand CmdObj = new SqlCommand(SqlCmd,conn);
CmdObj.Parameters.Add("@id",SqlDbType.VarChar);
CmdObj.Parameters.Add("@type",SqlDbType.Char);
CmdObj.Parameters.Add("@basetype",SqlDbType.Char);
foreach(DataRow row in data.Tables[0].Rows)
{
CmdObj.Parameters["@id"].Value=System.Guid.NewGuid().ToString();
CmdObj.Parameters["@type"].Value=row[0].ToString();
CmdObj.Parameters["@basetype"].Value=row[1].ToString();
CmdObj.Parameters["@contentpoint"].Value=row[2].ToString();
CmdObj.ExecuteNonQuery();
}
conn.Close();
}
{
try
{
if(InfoID.Text!=""&&InfoContent.Text!=""&&PerInfoID.Text!=""&&InfoCommand.Text!="")
{
sqlDataAdapter1.InsertCommand.CommandText="insert into Info("+"InfoID,InfoContent,PerInfoID,InfoCommand,Note"+") values("+InfoID.Text+",'"+InfoContent.Text+"',"+PerInfoID.Text+",'"+InfoCommand.Text+"','"+Note.Text+"')";
statusBar.Text="添加:"+sqlDataAdapter1.InsertCommand.CommandText;
sqlDataAdapter1.InsertCommand.ExecuteNonQuery();
statusBar.Text="添加成功";
}
else statusBar.Text="操作不正确";
}
catch( System.Data.SqlClient.SqlException)
{
statusBar.Text="添加出现异常";
}
catch( System.NullReferenceException)
{
statusBar.Text="添加出现异常";
}
}
为什么我执行这个动作,总是出现异常呢?
我反复检查过,SQL语句应该是没有错的.
请高手指点指点---------急用~!