asp.net 在gridview中显示上传数据时 报错:cmd.ExecuteNonQuery()用户代码未处理。。。
Dim fileName As String = System.IO.Path.GetFileName(FileUpload1.FileName)
Dim filesize As Integer = FileUpload1.FileBytes.Length
Dim filetime As Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
Dim username As String = "label1.text"
Dim cmd As SqlCommand
myconn = New SqlConnection("server=localhost;database=database;uid=sa;pwd=sa")
myconn.Open()
Dim sqlstr As String = "insert into file (filename,filesize,filetime,username) VALUES (@filename,@filesize,@filetime,@username)"
cmd = New SqlCommand(sqlstr, myconn)
cmd.Parameters.AddWithValue("@filename", fileName)
cmd.Parameters.AddWithValue("@filesize", filesize)
cmd.Parameters.AddWithValue("@filetime", filetime)
cmd.Parameters.AddWithValue("@username", username)
cmd.ExecuteNonQuery()
cmd = New SqlCommand("select * from file order by filetime", myconn)
Dim dr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
GridView1.DataSource = dr
GridView1.DataBind()
myconn.Close()
------解决方案--------------------
你改成
Dim sqlstr As String = "insert into [file] ([filename],[filesize],[filetime],[username]) VALUES (@filename,@filesize,@filetime,@username)"
试试