ewang1205
asked on
reuse CommandText
I have the following code. I try to reset CommandText SQL based on a condition. If ct = 1 Then reset CommandText SQL . But, I don't think it works. Can I change the SQL inside CommandText like that? Thanks.
CMD.Connection = conn
conn.Open()
CMD.CommandText = "SELECT count(*) ct FROM XX where LEASE='" & Request.QueryString("LEASE ") & "'"
da.SelectCommand = CMD
da.Fill(ds, "ContactRequests")
Dim ct As Integer = ds.Tables(0).Rows(0)("ct")
If ct = 1 Then
CMD.CommandText = "SELECT objID FROM XX where LEASE='" & Request.QueryString("LEASE ") & "'"
da.SelectCommand = CMD
da.Fill(ds, "ContactRequests")
Dim objID As String = ds.Tables(0).Rows(0)("objI D").ToStri ng()
end if
CMD.Connection = conn
conn.Open()
CMD.CommandText = "SELECT count(*) ct FROM XX where LEASE='" & Request.QueryString("LEASE
da.SelectCommand = CMD
da.Fill(ds, "ContactRequests")
Dim ct As Integer = ds.Tables(0).Rows(0)("ct")
If ct = 1 Then
CMD.CommandText = "SELECT objID FROM XX where LEASE='" & Request.QueryString("LEASE
da.SelectCommand = CMD
da.Fill(ds, "ContactRequests")
Dim objID As String = ds.Tables(0).Rows(0)("objI
end if
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
gregg1ep00: That is great. Faster and simpler and working great! Thanks.
conn.Close()