Bit Data type column from Database to ASP Data grid getting error Cast from type 'DbDataRecord' to type 'Boolean' is not valid.

I have bit Datatype column in my table and I am putting this table into ASP datagrid

 I have created a check box in thiscolumn in datagrid using itemtemplate.  so this bit column should have a check box next to it in datagrid

but I am getting this when running the app  Cast from type 'DbDataRecord' to type 'Boolean' is not valid.

any one know any thing about this issue

0
khana04
12/21/2006 12:32:36 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
1311 Views

Similar Articles

[PageSpeed] 13
Get it on Google Play
Get it on Apple App Store

Hi, khana04:

I am not sure about what you are going to do about convert DbDataRecord to Boolean. Would u please show us some code about  it. However, the following code works fine for me to retrive the bound checkbox's value.

sqlUpdateCommand1.Parameters["@Boolean"].Value
             = ((CheckBox)e.Item.Cells[4].Controls[0]).Checked;




Best Regards,
__________________________________________________
Sincerely,
Rex Lin
Microsoft Online Community Support

This posting is provided "AS IS" with on warranties, and confers no rights.
0
rexlin
12/21/2006 2:02:24 AM

Thanks for the info Rex below is code I used to make it work

 <asp:TemplateColumn HeaderText="Select">
      <ItemTemplate>
       <asp:CheckBox id=CheckBox1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Checked") %>' Checked='<%# DataBinder.Eval(Container, "Dataitem.Checked") %>'>
       </asp:CheckBox>
      </ItemTemplate>

Checked is the column bit Datatype column from SQl table. 

 

0
khana04
12/21/2006 8:55:04 AM
Reply:

Similar Artilces:

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'.
what is my problem? I'm working with GridView for sorting The error message is that "Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'".... Dim m_DataTable As DataTable = GridView1.DataSource How can I change the code above?   Well let's see, if your DataSource is a DataView, you can get its associated DataTable object using the .Table property: Dim m_DataTable As DataTable = GridView1.DataSource.Table or in a land of strict typing:  Dim m_DataTable As DataTable = CType(GridView1.DataSource, System.Data.DataView).Table   Hope tha...

Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'.
When I click the sort hyperlink, I got this error mesg: Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'.  in line 5.How do I fix this? Thanks. 1 Protected Sub GVCRlisting_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GVCRlisting.Sorting 2 GridViewSortExpression = e.SortExpression 3 Dim pageIndex As Integer = GVCRlisting.PageIndex 4 5 GVCRlisting.DataSource = SortDataTable(GVCRlisting.DataSource, False) 6 GVCRlisting....

Unable to cast object of type 'TYPE' to type 'TYPE'.
I've got a custom class and collection...I want to use them to databind a Grid, and persist the state using a Session variable.  However I keep getting the above error **Sometimes...There will be times when it works fine, and times when it totally craps out.System.InvalidCastException: Unable to cast object of type 'ApprovalCycleCollection' to type 'ApprovalCycleCollection'. This should work fine, no?  I want a property to use in all my foreach loops   public ApprovalCycleCollection NewApprovalCycle { get { if (Se...

Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.DataRowView'.
Hi... I have a ListView which is nested in the ItemTemplate of another ListView. If a "status" value in the inner ListView = 1, then I'd like to hide the "Add to cart" link. However, the inner ListView's ItemDataBound event results in the error: "Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.DataRowView'." I've thoroughly searched the forums, but have not found a solution to this seemingly straightforward problem. Here is the code; the error occurs at line 8. 1 protected void L...

Unable to cast object of type 'System.Boolean' to type 'System.Data.SqlClient.SqlParameter'.
In my code this doesn't work:prms(0) = New SqlParameter("@QUERYTYPE", Data.SqlDbType.Int).value = 2I get the error:Unable to cast object of type 'System.Boolean' to type 'System.Data.SqlClient.SqlParameter'. But this does: prms(0) = New SqlParameter("@QUERYTYPE", Data.SqlDbType.Int)prms(0).Value = 2Any reason why?  You code prms(0) = New SqlParameter("@QUERYTYPE", Data.SqlDbType.Int).value = 2 do evaluation: 1. if New SqlParameter("@QUERYTYPE", Data.SqlDbType.Int).value = 2, the result is Yes or No, 2. prms(0) =...

Error type 'System.Data.DataTable' to type 'PRODUCT_LISTDataTable'
I can't figure this one out. I created new solution in vs2005 from using vs2003 and I have a problem I can't find an answer to. I get the following error that relates to passing a system.data.datatable to a dataset.datatable named "ProductList.PRODUCT_LISTDataTable".  It says it can't cast the object from one type to the other, and I've tried "CType" and doesn't work. Error: Unable to cast object of type 'System.Data.DataTable' to type 'PRODUCT_LISTDataTable'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trac...

Error:Cast from type 'DBNull' to type 'Date' is not valid
I tried to insert a null date of birth value to SQL Server table, the datatype is smalldatetime in the table.  I found it insert 1/1/1900 instead of null value.  So I am trying to fix it by the following way: In the first .aspx page, I stored DOB in a session value:  If txtDOB.Text = Nothing Then    Session("DOB") = DBNull.Value Else    Session("DOB") = txtDOB.Text End If In the 2nd .aspx page, I get the value by:  Dim Birthday As Date = CDate(Session("DOB")) However, I got an error message :System.InvalidCastException: Cast fro...

Cast from type 'DBNull' to type 'String' is not valid. Error
Hi, Can anyone help me with an error I am receiving "Cast from type 'DBNull' to type 'String' is not valid."  I am creating an aspx page in VB.NET, please find attached code causing error.objCmd = New SqlCommand("USP_DisplayEmbarkDetails", objConn)  objCmd.CommandType = CommandType.StoredProcedure  objCmd.Parameters.Add("@BranchID", lblGetBranchID.Text)  objConn.Open()  objRdr = objCmd.ExecuteReader()    While objRdr.Read     lblBranchName.Text=objRdr("BranchName")    lblBranchID.Text=objRd...

Error : Cast from type 'DBNull' to type 'Integer' is not valid
Hi all,         I have beign figure the error for days but still cant figure out what's went wrong and no idea how to solve this error : Cast from type 'DBNull' to type 'Integer' is not valid. This is what i want to do :1.Display the number of item added into the shopping cart retrieved from the database. (workable)2.If there is qty eg. 2 in the shopping cart,it will display 2 items.(workable)3.But when i remove all the items in the shopping cart,this error : Cast from type 'DBNull' to type 'Integer' is not valid occured4. Anyone knows what code should...

Error
I have a FormView with default mode as "Edit" which allows users to edit a specific record or add new records. Its working fine except for the records which have Null value in their field "Mresponsible". This "MResponsible" is a bit field and allows Nulls. So, some of the existing reocrds have Null value in this field. When I click on "Select" link on my first page "List.aspx" to come to this "AddEdit.aspx", if its a record with Null value in that field it shows me the error - Conversion from type 'DBNull' to type 'Boolean' is not valid.  Any inputs to solve this? Thanks for...

SqlDataSource.Select Error: Unable to cast object of type 'System.Data.DataView' to type 'System.String'.
I am trying to put the data from a field in my database into a row in a table using the SQLDataSource.Select statement. I am using the following code: FileBase.SelectCommand = "SELECT Username FROM Files WHERE Filename = '" & myFileInfo.FullName & "'" myDataRow("Username") = CType(FileBase.Select(New DataSourceSelectArguments()), String)But when I run the code, I get the following error:Server Error in '/YorZap' Application. Unable to cast object of type 'System.Data.DataView' to type 'System.String'. Descri...

SqlDataSource.Select Error: Unable to cast object of type 'System.Data.DataView' to type 'System.String'.
I am trying to use the select statement to put a field from my database using a SqlDataSource named 'FileBase.' I am using the following code: FileBase.SelectCommand = "SELECT Username FROM Files WHERE Filename = '" & myFileInfo.FullName & "'" myDataRow("Username") = CType(FileBase.Select(New DataSourceSelectArguments()), String)But when I run the code I get the following error:Server Error in '/YorZap' Application. Unable to cast object of type 'System.Data.DataView' to type 'System.String'. Description:...

Cannot convert type 'type' to 'type'
I am learning all of this, so I am still fresh, so please bear with me :)I have a page that has some txtboxes in it, simple registration form, and I have a button that will save those txt boxes to the db. I am using:- I am using Visual Web Developer 2008 Express Edition- C# When I try to compile the project I get error: Cannot convert type 'System.Web.UI.WebControls' to 'String' This is content of my web.config    <profile> <properties> <add name="FirstName"/> <add name="LasttName"/>...

Unable to cast object of type 'System.Data.DataRow' to type 'OrderRow'
I'm trying to follow through the “Nested Data Web Controls” tutorial on this site but using data from my database rather than Northwind. For the two repeaters I am using an SQLDatasource for the outer repeater and an objectdatasource for the inner repeater.   I'm as far as the casting in the outer-repeaters ItemDataBound event but getting an InvalidCastException with the message:   “Unable to cast object of type 'System.Data.DataRow' to type 'OrderRow'”   As far as I can see, the only deviation from the tutorial is that I am using an SQLDatasource ...

Web resources about - Bit Data type column from Database to ASP Data grid getting error Cast from type 'DbDataRecord' to type 'Boolean' is not valid. - asp.net.presentation-controls

Resources last updated: 1/13/2016 10:03:52 AM