CREATE PROCEDURE FindBookByAuthor
@.Aname char
AS
select b.libcode, b.title, b.subject, a.authorname, b.instock
from bookinfo b join authorinfo a
on b.authorid = a.authorid
where a.authorname like '%' + @.aname + '%'
GO
I have tested this procedure changing the variable @.aname for the surname of the author. This works fine. The problem comes when I execute this procedure from web matrix. I use a textbox to obtain the data for the variable @.aname. I send the data. What happens is that when I run the web page and look for a book through the author the select statement behaves differently and gives me a different output.
I would be glad to know why this happens
ThanksShow some code. Failing that, verify in SQL Profiler that the SQL/Parameters you think you are executing is in fact what is being executed.|||well, the asp.net code is :
--------------------
Sub Button2_Click(sender As Object, e As EventArgs)
Dim objConn As SqlConnection
Dim dataReader As SqlDataReader
dim constring as string
Dim objCmd As SqlCommand
constring = "server='(local)'; trusted_connection=true; database='dbjaime'"
objConn = New sqlconnection(constring)
dim strsql as string
strsql = "EXECUTE findtitle '" & textboxtitle.text & "'"
objCmd = New SqlCommand(strSQL, objConn)objConn.Open()
dataReader = objCmd.ExecuteReader()
'Bind to DataGrid
dtgbooks.DataSource = dataReader
dtgbooks.DataBind()objConn.Close()
objConn.Dispose()
End Sub
--------------------
Where "findtitle" is a procedure I showed you before.|||Use SQL Profiler and see if what you are sending is what you think you are in both cases (where it works and where it does not).|||I have tried to use the sql profiler, which I had never used before. It shows me the last executions. Then I have loaded my web page and execute the event "button click" I send you before. Now what I see on the sql profile is:
exec sp_executesql N'EXECUTE findtitle ''design'''
among other stuff. I this what I should get?|||The findtitle line is what I was having you look for.
Execute the code in the way that it works, as well as the way that it does not work, and compare what appears in SQL Profiler. You are saying running the code with Web Matrix produces different results. I am looking to have you isolate exactly why the results are different.|||ok. I'll take a look. Thanks for being so quick.|||I'm not sure if I'm passing the parameters correctly to the procedure findtitle on the line:
strsql = "EXECUTE findtitle ' " & txt1.text & " ' "
I say that they give me different results because when I copy the select statement from the procedure into the SQL analyzer I subtitute the variabe @.btitle for a word such as 'database'. And then, when I execute the web page I insert in the textbox the word database.
am I doing something wrong?
Thanks
No comments:
Post a Comment