Hi,
I am trying to run the following code in ASP.NET, using SqlDataAdapter to fetch a specific row and then update the data in that row.
But when I run the code, it returns no row in line 20, and no error occured.
Then I try to debug. I found that after I removed LINE 17 "da.FillSchema(osTable, SchemaType.Source)", the dataAdapter correctly returned a row that I wanted to. But I cannot update the row data after removing da.FillSchema, because an error "Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand" will occur.
So what can I do to do select and update in dataAdapter? I'm using ASP.NET 2.0, SQL SERVER 2005 EXPRESS SP2, .net framework 3.5 SP1.
Thanks,
Ronald
1 Using dbconn = New SqlConnection(ConfigurationManager.ConnectionStrings("shop").ConnectionString)
2 dbconn.Open()
3
4 Dim tran As SqlTransaction = dbconn.BeginTransaction
5 Dim osTable As New DataTable()
6 Dim SalaryID As New Guid(Request.Form("g"))
7
8 Using da As New SqlDataAdapter("select * from Employment WHERE id= @id", dbconn)
9 da.SelectCommand.Parameters.Add("@id", SqlDbType.UniqueIdentifier)
10 da.SelectCommand.Parameters("@id").Value = SalaryID
11 da.SelectCommand.Transaction = tran
12 da.SelectCommand.Prepare()
13
14 Dim builder As SqlCommandBuilder = New SqlCommandBuilder(da)
15 builder.ConflictOption = ConflictOption.OverwriteChanges
16
17 da.FillSchema(osTable, SchemaType.Source)
18 da.Fill(osTable)
19
20 If osTable.Rows.Count <= 0 Then Response.Write("NO DATA") Else Response.Write(osTable.Rows(0).Item(0))
21 End Using
22 End Using
23