System.InvalidOperationException: ExecuteReader: CommandText 屬性尚未初始化 at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean executing) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at ASP.NewFile_aspx.DataGrid_Update(Object Sender, DataGridCommandEventArgs E)我的代碼:Sub DataGrid_Update(Sender As Object, E As DataGridCommandEventArgs) ' update the database with the new values ' get the edit text boxes
Dim s_id As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim s_materialno As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim s_reportno As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
Dim s_productname As String = CType(e.Item.Cells(5).Controls(0), TextBox).Text
Dim s_manufacturer As String = CType(e.Item.Cells(6).Controls(0), TextBox).Text
Dim s_category As String = CType(e.Item.Cells(7).Controls(0), TextBox).Text
Dim s_method As String = CType(e.Item.Cells(8).Controls(0), TextBox).Text
Dim s_deliverby As String = CType(e.Item.Cells(9).Controls(0), TextBox).Text
Dim s_tester As String = CType(e.Item.Cells(10).Controls(0), TextBox).Text
Dim s_preapp As String = CType(e.Item.Cells(11).Controls(0), TextBox).Text
Dim s_approve As String = CType(e.Item.Cells(12).Controls(0), TextBox).Text
Dim s_deliverdate As String = CType(e.Item.Cells(13).Controls(0), TextBox).Text
Dim s_result As String = CType(e.Item.Cells(14).Controls(0), TextBox).Text ' TODO: update the Command value for your application
Dim myConnection As New SqlConnection(ConnectionString)
Dim UpdateCommand As SqlCommand = new SqlCommand()
UpdateCommand.Connection = myConnection If AddingNew = True Then
'UpdateCommand.CommandText = "INSERT INTO authors(au_id, au_lname, au_fname, contract) VALUES (@au_id, @au_lname, @au_fname, 0)"
'Else
'UpdateCommand.CommandText = "UPDATE authors SET au_lname = @au_lname, au_fname = @au_fname WHERE au_id = @au_id"
UpdateCommand.CommandText = "UPDATE Icp_report SET s_materialno = @s_materialno, s_reportno = @s_reportno,s_productname = @s_productname, s_manufacturer = @s_manufacturer,s_category = @s_category, s_method = @s_method,s_deliverby = @s_deliverby, s_tester = @s_tester,s_preapp = @s_preapp, s_approve = @s_approve,s_deliverdate = @s_deliverdate, s_result = @s_result, WHERE s_id = @s_id"
End If 'UpdateCommand.Parameters.Add("@au_id", SqlDbType.VarChar, 11).Value = id
'UpdateCommand.Parameters.Add("@au_lname", SqlDbType.VarChar, 40).Value = lname
'UpdateCommand.Parameters.Add("@au_fname", SqlDbType.VarChar, 20).Value = fname
UpdateCommand.Parameters.Add("@s_id", SqlDbType.VarChar, 11).Value = s_id
UpdateCommand.Parameters.Add("@s_materialno", SqlDbType.VarChar, 40).Value = s_materialno
UpdateCommand.Parameters.Add("@s_reportno", SqlDbType.VarChar, 20).Value = s_reportno UpdateCommand.Parameters.Add("@s_productname", SqlDbType.VarChar, 11).Value = s_productname
UpdateCommand.Parameters.Add("@s_manufacturer", SqlDbType.VarChar, 40).Value = s_manufacturer
UpdateCommand.Parameters.Add("@s_category", SqlDbType.VarChar, 20).Value = s_category UpdateCommand.Parameters.Add("@s_method", SqlDbType.VarChar, 11).Value = s_method
UpdateCommand.Parameters.Add("@s_deliverby", SqlDbType.VarChar, 40).Value = s_deliverby
UpdateCommand.Parameters.Add("@s_tester", SqlDbType.VarChar, 20).Value = s_tester UpdateCommand.Parameters.Add("@s_preapp", SqlDbType.VarChar, 11).Value = s_preapp
UpdateCommand.Parameters.Add("@s_approve", SqlDbType.VarChar, 40).Value = s_approve
UpdateCommand.Parameters.Add("@s_deliverdate", SqlDbType.VarChar, 20).Value = s_deliverdate
UpdateCommand.Parameters.Add("@s_result", SqlDbType.VarChar, 20).Value = s_result
' execute the command
Try
myConnection.Open()
UpdateCommand.ExecuteNonQuery() Catch ex as Exception
Message.Text = ex.ToString() Finally
myConnection.Close() End Try ' Resort the grid for new records
If AddingNew = True Then
DataGrid1.CurrentPageIndex = 0
AddingNew = false
End If ' rebind the grid
DataGrid1.EditItemIndex = -1
BindGrid()End Sub
Dim s_id As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim s_materialno As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim s_reportno As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
Dim s_productname As String = CType(e.Item.Cells(5).Controls(0), TextBox).Text
Dim s_manufacturer As String = CType(e.Item.Cells(6).Controls(0), TextBox).Text
Dim s_category As String = CType(e.Item.Cells(7).Controls(0), TextBox).Text
Dim s_method As String = CType(e.Item.Cells(8).Controls(0), TextBox).Text
Dim s_deliverby As String = CType(e.Item.Cells(9).Controls(0), TextBox).Text
Dim s_tester As String = CType(e.Item.Cells(10).Controls(0), TextBox).Text
Dim s_preapp As String = CType(e.Item.Cells(11).Controls(0), TextBox).Text
Dim s_approve As String = CType(e.Item.Cells(12).Controls(0), TextBox).Text
Dim s_deliverdate As String = CType(e.Item.Cells(13).Controls(0), TextBox).Text
Dim s_result As String = CType(e.Item.Cells(14).Controls(0), TextBox).Text ' TODO: update the Command value for your application
Dim myConnection As New SqlConnection(ConnectionString)
Dim UpdateCommand As SqlCommand = new SqlCommand()
UpdateCommand.Connection = myConnection If AddingNew = True Then
'UpdateCommand.CommandText = "INSERT INTO authors(au_id, au_lname, au_fname, contract) VALUES (@au_id, @au_lname, @au_fname, 0)"
'Else
'UpdateCommand.CommandText = "UPDATE authors SET au_lname = @au_lname, au_fname = @au_fname WHERE au_id = @au_id"
UpdateCommand.CommandText = "UPDATE Icp_report SET s_materialno = @s_materialno, s_reportno = @s_reportno,s_productname = @s_productname, s_manufacturer = @s_manufacturer,s_category = @s_category, s_method = @s_method,s_deliverby = @s_deliverby, s_tester = @s_tester,s_preapp = @s_preapp, s_approve = @s_approve,s_deliverdate = @s_deliverdate, s_result = @s_result, WHERE s_id = @s_id"
End If 'UpdateCommand.Parameters.Add("@au_id", SqlDbType.VarChar, 11).Value = id
'UpdateCommand.Parameters.Add("@au_lname", SqlDbType.VarChar, 40).Value = lname
'UpdateCommand.Parameters.Add("@au_fname", SqlDbType.VarChar, 20).Value = fname
UpdateCommand.Parameters.Add("@s_id", SqlDbType.VarChar, 11).Value = s_id
UpdateCommand.Parameters.Add("@s_materialno", SqlDbType.VarChar, 40).Value = s_materialno
UpdateCommand.Parameters.Add("@s_reportno", SqlDbType.VarChar, 20).Value = s_reportno UpdateCommand.Parameters.Add("@s_productname", SqlDbType.VarChar, 11).Value = s_productname
UpdateCommand.Parameters.Add("@s_manufacturer", SqlDbType.VarChar, 40).Value = s_manufacturer
UpdateCommand.Parameters.Add("@s_category", SqlDbType.VarChar, 20).Value = s_category UpdateCommand.Parameters.Add("@s_method", SqlDbType.VarChar, 11).Value = s_method
UpdateCommand.Parameters.Add("@s_deliverby", SqlDbType.VarChar, 40).Value = s_deliverby
UpdateCommand.Parameters.Add("@s_tester", SqlDbType.VarChar, 20).Value = s_tester UpdateCommand.Parameters.Add("@s_preapp", SqlDbType.VarChar, 11).Value = s_preapp
UpdateCommand.Parameters.Add("@s_approve", SqlDbType.VarChar, 40).Value = s_approve
UpdateCommand.Parameters.Add("@s_deliverdate", SqlDbType.VarChar, 20).Value = s_deliverdate
UpdateCommand.Parameters.Add("@s_result", SqlDbType.VarChar, 20).Value = s_result
' execute the command
Try
myConnection.Open()
UpdateCommand.ExecuteNonQuery() Catch ex as Exception
Message.Text = ex.ToString() Finally
myConnection.Close() End Try ' Resort the grid for new records
If AddingNew = True Then
DataGrid1.CurrentPageIndex = 0
AddingNew = false
End If ' rebind the grid
DataGrid1.EditItemIndex = -1
BindGrid()End Sub
解决方案 »
- 有关图片预览的问题,求解。
- asp.net 调用另一个页面函数?
- 在GridView的RowUpdating 事件中e.NewValues.Count是0。怎么回事?
- 140多列的gridview,会出问题吗
- 各位高人谁买了《asp.net+ado.net项目开发实例》一书了?我怎么下载不到源码?
- 行业、门户类的网站
- 在Windows 2003 Server的IIS6.0下ASP.NET执行安全性的问题
- 怎么入门ASP.NET
- 不使用控件如何访问数据库?
- 请问如果我做个项目,难道要在VS.NET里面做网页吗?
- RequiredFieldValidator验证控件的疑问!!!
- 文件下载时遇到的一个问题
行 124: Dim s_deliverdate As Date = CType(e.Item.Cells(12).Controls(0), TextBox).Text
-----------------------------
你这个是转换为什么?转换为时间吗?好像不太象,转换为文本框吗?前面定义的又不是
Dim s_deliverdate As TextBox = CType(e.Item.Cells(12).Controls(0), TextBox)
值 = s_deliverdate.Text
為什麼我這裡寫的時候沒有呢,
Dim r As DataSet1.icp_reportRow
r = DataSet11.icp_report.後面沒有Findby這個方法,