Quantcast
Channel: DataSource Controls - SqlDataSource, ObjectDataSource, etc.
Viewing all articles
Browse latest Browse all 956

SqlDataSource.SelectParameters with variable or session from MySqlDataReader return nothing

$
0
0

Sorry for my english !

When I click on button 

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

ReadMyData(ConfigurationManager.ConnectionStrings("myconnection").ConnectionString)

End Sub

After

Public Sub ReadMyData(myConnString As String)

Dim myVariable As String = ""

Dim myConnection As New MySqlConnection(myConnString)
Dim myCommand As New MySqlCommand("mystoreprocedure", myConnection)

myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.AddWithValue("@pMyparam", "9063")

myConnection.Open()
Dim myReader As MySqlDataReader
myReader = myCommand.ExecuteReader()
' Always call Read before accessing data.
While myReader.Read()


myVariable  = myReader.GetString(0)

End While

Session("mySession") = myVariable
Me.SqlDataSource.SelectParameters(0).DefaultValue = Session("mySession")
Me.SqlDataSource.DataBind()

myReader.Close()
myConnection.Close()

End Sub 

My SqlDataSource and my datalist is always get nothing, I check everthing my datareader return 1234 and  myVariable  = 123

if I put like 
Me.SqlDataSource.SelectParameters(0).DefaultValue = "1234" instead is work perfectly.

Please help me , thank you 


Viewing all articles
Browse latest Browse all 956

Trending Articles