PDA

View Full Version : کمک فوری بدست آوردن اطلاعات با استفاده از session



afaghmoh
شنبه 12 آذر 1384, 12:51 عصر
نیاز به کمک فوری دارم من برای انتقال اطلاعات از session استفاده می کنم اکنون می خواهم این سیشن را در یک شر ط بگذارم پیغام خطا میدهد کد من به صورت زیر است
Dim code2 As String
Dim dr As SqlDataReader
Dim con As SqlConnection
Dim cmd As SqlCommand
con = New SqlConnection("server=universi-16beff\sqlhelp;UID=sa;database=savabegh")
str = "Select * from t1 where a1=@code2"
code2 = Session("code")
cmd = New SqlCommand(str, con)
con.Open()
dr = cmd.ExecuteReader()
dr.Read()
t1.Text = dr("a2")
t2.Text = dr("a3")
t3.Text = dr("a4")
t4.Text = dr("a5")
t14.Text = dr("a6")
con.Close()
dr.Close()
و پیغام خطا به صورت زیر است



Must declare the variable '@code2'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Must declare the variable '@code2'.

Source Error:


Line 87: cmd = New SqlCommand(str, con)
Line 88: con.Open()
Line 89: dr = cmd.ExecuteReader()
Line 90: dr.Read()
Line 91: t1.Text = dr("a2")



Session("code"(این متغییری است که از صفحه قبلی وارد می شود

m_nejad
شنبه 12 آذر 1384, 15:48 عصر
این جوری بنویسی چه طوره؟
("str = "Select * from t1 where a1=" & Session("code

Behrouz_Rad
شنبه 12 آذر 1384, 16:22 عصر
شما پارامتری به نام Code2@ رو تعریف کردی اما ایجاد و مقداردهیش نکردی!


Dim param As SqlParameter;
param = myCommand.Parameters.Add("@code2", SqlDbType.Int);
param.Value = myIntegerValue;

موفق باشید.