472,805 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

error Unable to cast object of type 'System.Data.DataColumn' to type 'System.IConvert

11
hi friends,
i have one class and i have created two properties

and filled this property through dataset

but when i created object o this class to access this property to fill textbox

i am geting this problem

"Unable to cast object of type 'System.Data.DataColumn' to type 'System.IConvertible"

Please give me suggestion

Expand|Select|Wrap|Line Numbers
  1. public class Class1
  2. {
  3.     SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cnstr"]);
  4.     SqlDataAdapter da = new SqlDataAdapter();
  5.     SqlCommand cmd = new SqlCommand();
  6.     DataSet ds = new DataSet();
  7.     SqlDataReader dr;
  8.     public Class1()
  9.     {
  10.         //
  11.         // TODO: Add constructor logic here
  12.         //
  13.     }
  14.        public void getdata1()
  15.     {
  16.         cmd.Connection = cn;
  17.         cn.Open();
  18.         cmd.CommandType = CommandType.Text;
  19.         cmd.CommandText = "SELECT EmployeeID, FirstName FROM    employees ORDER BY FirstName";
  20.         da.SelectCommand = cmd;
  21.         da.Fill(ds);
  22.  
  23.         this._CategoryId = Convert.ToInt16(ds.Tables[0].Columns["employeeid"]);
  24.         this._firstname = ds.Tables[0].Columns["firstname"].ToString();
  25.  
  26.  
  27.  
  28.        private int _CategoryId;
  29.  
  30.     public int CategoryId
  31.     {
  32.         set { _CategoryId = value; }
  33.         get { return _CategoryId; }
  34.     }
  35.     private string _firstname;
  36.  
  37.     public string firstname
  38.     { 
  39.         set { _firstname = value; }
  40.         get { return _firstname; }
  41.  
  42.     }
  43.     private string _lastname;
  44.  
  45.     public string lastname
  46.     {   
  47.         set { _lastname = value; }
  48.         get { return _lastname; }
  49.  
  50.     }
  51.  
this is my .cs file code

Expand|Select|Wrap|Line Numbers
  1. Class1 objcls = new Class1();
  2.  this.objcls.getdata1();
  3.  
  4.         txtid.Text = objcls.CategoryId.ToString();
  5.         txtname.Text = objcls.firstname.ToString();
Dec 7 '07 #1
0 3847

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Pankaj Jain | last post by:
Hi All, I have a class A which is derived from ServicesComponent to participate in automatic transaction with falg Transaction.Required. Class A is exposed to client through remoting on Http...
4
by: Richard Lee | last post by:
Hi, I have a question when I do a data type cast. the common way when we do a cast, is we know the type we want to cast to, i.e. we want to cast object to string, object xyz = "question";...
0
by: Dave Elliott | last post by:
After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is after the newly added row without getting bizarre results. I have added the...
20
by: MadCrazyNewbie | last post by:
Hey group, I keep getting the following error: "An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll Additional information: There is no row at...
3
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something...
0
by: Wes Shaddix | last post by:
I have a vendor web service that I have created a web application to interact with. The service works fine in VS 2003 but fails in VS 2005. I have implemented a proxy between the web client and...
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
1
by: explode | last post by:
My table has 5 columns: Broj iksice, Prezime, Ime, Broj indeksa, Broj pohadjanja. This is the code in the dataset designer VB made it by it self: Private Sub InitClass() Me.columnBroj_iksice =...
0
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.