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
- public class Class1
-
{
-
SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cnstr"]);
-
SqlDataAdapter da = new SqlDataAdapter();
-
SqlCommand cmd = new SqlCommand();
-
DataSet ds = new DataSet();
-
SqlDataReader dr;
-
public Class1()
-
{
-
//
-
// TODO: Add constructor logic here
-
//
-
}
-
public void getdata1()
-
{
-
cmd.Connection = cn;
-
cn.Open();
-
cmd.CommandType = CommandType.Text;
-
cmd.CommandText = "SELECT EmployeeID, FirstName FROM employees ORDER BY FirstName";
-
da.SelectCommand = cmd;
-
da.Fill(ds);
-
-
this._CategoryId = Convert.ToInt16(ds.Tables[0].Columns["employeeid"]);
-
this._firstname = ds.Tables[0].Columns["firstname"].ToString();
-
-
-
-
private int _CategoryId;
-
-
public int CategoryId
-
{
-
set { _CategoryId = value; }
-
get { return _CategoryId; }
-
}
-
private string _firstname;
-
-
public string firstname
-
{
-
set { _firstname = value; }
-
get { return _firstname; }
-
-
}
-
private string _lastname;
-
-
public string lastname
-
{
-
set { _lastname = value; }
-
get { return _lastname; }
-
-
}
-
this is my .cs file code
- Class1 objcls = new Class1();
-
this.objcls.getdata1();
-
-
txtid.Text = objcls.CategoryId.ToString();
-
txtname.Text = objcls.firstname.ToString();