diGeE Posted December 22, 2003 Posted December 22, 2003 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. Quote
evaleah Posted December 29, 2003 Posted December 29, 2003 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...... Quote
Administrators PlausiblyDamp Posted December 29, 2003 Administrators Posted December 29, 2003 Why have you parameterised the procedure - you never use the @TFUname parameter in the body of the proc anywhere. Also why whould you expect the letter 'F' to be accepted as an integer, is the underlying field an integer or a letter? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.