.net2.0 里要如何在FormView里使用FileUpload上传图片至Sql2005?
FormView fv = (FormView)sender;FileUpload FU = (FileUpload)fv.FindControl("FileUpload1");
TextBox tn = (TextBox)fv.FindControl("NumTextBox");
byte[] Images = new byte[FU.PostedFile.InputStream.Length];
FU.PostedFile.InputStream.Read(Images, 0, Images.Length);
if (Images.Length > 0)
{
string connString = ConfigurationManager.ConnectionStrings["test"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
conn.Open();
SqlTransaction tran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand("inser into test(Num,Image) Values (@Num,@Image)");
cmd.Transaction = tran;
try
{
cmd.Parameters.Add("@Num", SqlDbType.Text).Value = tn.Text;
cmd.Parameters.Add("@Image",SqlDbType.Image).Value = Images;
cmd.ExecuteNonQuery();
tran.Commit(); //确认事务
}
catch
{
tran.Rollback(); //回复事务
}
cmd.Dispose();
conn.Close();
conn.Dispose();
}
以上代码错在哪?请高手指教! --------------------编程问答-------------------- 接分了 --------------------编程问答-------------------- lz要干嘛?
补充:.NET技术 , Web Services