For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Tuesday, June 28, 2016

Object must be of type String while sorting datagridview

Object must be of type String

You are working with DataGridView with  several columns. You want to make sort of one column name "marks". then you will simply use below one line of code:

dataGridView1.Sort(dataGridView1.Columns["marks"], ListSortDirection.Ascending); 


But you may get error message as below:

System.ArgumentException was unhandled
  Message="Object must be of type String."
  Source="mscorlib"
  StackTrace:
       at System.String.CompareTo(Object value)
       at System.Collections.Comparer.Compare(Object a, Object b)
       at 
       .......................................
       .......................................
       at System.Threading.ThreadHelper.ThreadStart()

  InnerException: 

Let me try to understand you why the error message "Object must be of type String." You are getting when sorting "marks".

Very first time You are getting data from database and storing in the your datagridview something like this, note that string marks:

string marks = ds.Tables[0].Rows[grid_sr_no]["marks"].ToString();
dataGridView1.Rows[i].Cells["marks"].Value = mark;


after some processing in the seconds time you are string marks as intereger like this:

int marks = Convert.ToInt32(ds1.Tables[0].Rows[0]["marks"].ToString());
dataGridView1.Rows[i].Cells["marks"].Value = marks;


Then after if you use sorting code as below:
dataGridView1.Sort(dataGridView1.Columns["marks"], ListSortDirection.Ascending); 

You will get error message:
System.ArgumentException was unhandled
 Message="Object must be of type String."


so, to overcome this problem only use similar datatype while storing in datagridview.
alternatively you can use below code:
dataGridView1.Rows[i].Cells["marks"].Value = marks.ToString();






Share:

Software caused connection abort Failed to retrieve directory listing in FileZilla

Software caused connection abort Failed to retrieve directory listing in FileZilla

FileZilla is a Good software for FTP and SFTP to upload and download files in web-server. sometime in a folder having lot of files for ex: >50000 at that time when you want to see those files simply you double click on that folder. but you surprised that you will get below message:

"Network error: Software caused connection abortError: Failed to retrieve directory listing"

to solve above problem you need to set something in your FilZilla. follow below steps:
1- Open FileZilla 
2- Click on Edit menu => Setting 
3- Choose "Connection" and then in right side put 9999 in the box of "Timeout in seconds".

Share:

How to use $_POST in better way

How to use $_POST in better way.

Suppose there are 10 fields in a PHP webpage that's data are saving into database.
In that 10 fields 2 fields are empty and when in values are empty you want store "N/A" values are saving into database. 

Use below one line of code:
$myval = isset( $_POST['myvar'] ) ? $_POST['myvar'] : 'N/A'; 


You can use this logic in any website programming language.



Share:

Multiple attribute passing in querySelectorAll

Multiple attribute passing in querySelectorAll     Here I am demonstrating code to how to pass multiple attributes in querySelectorAll. <...

Ads Inside Post

Powered by Blogger.

Arsip