Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm pulling information from a database to pull to a datagrid. And after you click the item in the datagrid, it populates on the next page. The item that I'm pulling is a string, but my page will only work if i set it to an integer. Like this:

 

Public Function TFGetTFuse(ByVal TFUname As Integer)

 

' Create Instance of Connection and Command Object

Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))

 

' Generate Command Object based on Method

Dim myCommand As SqlCommand = SqlCommandGenerator.GenerateCommand(myConnection, _

CType(MethodBase.GetCurrentMethod(), MethodInfo), _

New Object() {TFUname})

 

' Execute the command

myConnection.Open()

Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

 

' Return the datareader=20

Return result

 

End Function

 

Then I bring it to the page like this:

 

Sub BindTFUse()

Dim ds As DataSet = ConvertDataReaderToDataSet(_TollFreeDB.TFGetTFuse(TFUname))

 

txtTFUse.DataSource = ds

txtTFUse.DataTextField = "TFUname"

txtTFUse.DataValueField = "TFU_Key"

txtTFUse.DataBind()

ds.Dispose()

 

 

End Sub

 

and I bind in the page load. So then to populate i use this:

 

txtTFUse.SelectedIndex = e.Item.Cells(3).Text()

 

 

My problem is that the item that is being populated is from a "sub" table. ex: F = Front end. My value on the main table is "F". and when i try to bring the value through and populate i get this error:

 

InvalidCastException: Cast from string "F" to type 'Integer' is not valid.]

 

 

but if i were to set the value of the db connection to string, then it craps out completely. Please help.

 

 

my stored procedure:

 

CREATE PROCEDURE dbo.TFGetTFUse

 

@TFUname nvarchar(50)

 

AS

 

select TFU_Key, TFUname

from [TollFreeData].dbo.TFuseLKU

 

 

thank you.

Posted

The way I understand your problem you are trying to bind a non-integer field to a DataValue field on a datagrid and that is where the error is occurring?

 

For my part, I get a bit confused in your conversions of the data. Why not bring the data straight to the grid as a dataset? Why the conversion? Does it work if you run the query that way?

 

Just a place to start......

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...