How to fix this message

Verno

Member
Joined
Jan 5, 2020
Messages
10
Programming Experience
1-3
please whenever I load this window, it shows me this message, new that I'm on C #, I don't know how to solve it.
please Help me
 

Attachments

  • NH.png
    NH.png
    44.4 KB · Views: 37
It appears that you have an image column in your grid but the data bound to it is not valid images. We can't really be more specific than that without knowing about the data and how it is bound to the grid.
 
It's telling you your parameter is not valid. What value type is it, and how are you parsing that value, and as what type of object?
 
It appears that you have an image column in your grid but the data bound to it is not valid images. We can't really be more specific than that without knowing about the data and how it is bound to the grid.
I don't have image column in my table.....
 
That callstack that is shown suggests otherwise. It would help a lot if you shared your code so that we can see what you are trying to do.
 
when i launch the window, image 1 is displayed with this error then when i click on the ok button, the dgv fills up but after another interaction it stops.this is the code for the from
C#:
//Create new instance
        UserDAL dal = new UserDAL();
        clsUser userDel = new clsUser();
        Interfaces intl = new Interfaces();
        
      
        private void frmSUsers_Load(object sender, EventArgs e)
        {
            dgvUsers.DataSource = dal.Select("users", dgvUsers);
            panTextResearch.Size = new Size(1118, 51);
            panAdvancedResearch.Visible = false;
        }

        ///the dal.select method
public DataTable   Select(string table, DataGridView dgv)
        {
          

            try
            {
                string sqlRequest = "SELECT id,gender as 'GENDER',first_name as 'FIRST NAME',last_name as 'LAST NAME',email as 'EMAIL',username as 'USERNAME' ,password,contact as 'PHONE',address,user_type as 'USER TYPE',added_date,added_by FROM tbl_" + table;
                sqlCon = new SqlConnection(myConn);
                ///
                Connect();
                ///
                cmd = new SqlCommand(sqlRequest, sqlCon );
                ///
                ds = new DataSet();
                dta = new SqlDataAdapter(cmd);
                ///
                dt = new DataTable();
                dta.Fill(dt);

                ///dgv.DataSource = dt;

              

                //Personnalize column name
                DataTableMapping map = new DataTableMapping("tbl_"+table , "tbl"+table );
                map.ColumnMappings.Add("id", "ID");
                map.ColumnMappings.Add("user_type", "User Type");
                map.ColumnMappings.Add("gender", "Gender");
                map.ColumnMappings.Add("first_name", "First Name");
                map.ColumnMappings.Add("last_name", "Last Name");
                map.ColumnMappings.Add("username", "Username");
                map.ColumnMappings.Add("email", "Email");
                map.ColumnMappings.Add("contact", "Phone");

                //Add mapping to table
                dta .TableMappings.Add(map);
                //hide some columns
                //  dgv.Columns["id"].Visible = false;
                //  this.dgvUsers.Columns["added_date"].Visible = false;
                //this.dgvUsers.Columns["added_by"].Visible = false;
                //this.dgvUsers.Columns["password"].Visible = false;
                
            }
            catch(Exception e1)
            {
                MessageBox.Show(e1.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Information  );
            }
            finally
            {
                Disconnect();
                dta.Dispose();
            }

            return dt;
        }
 

Attachments

  • 1.png
    1.png
    53.8 KB · Views: 27
  • 2.png
    2.png
    30.1 KB · Views: 24
When you bind data to a grid and allow the grid to create the columns for you, it will create an image column if one of the source columns contains binary data. Your screenshots indicate that the eleventh column is such a column. You need to use the debugger and actually look at your DataTable to see where that binary data is and work out why it's there if it shouldn't be. If it should be there then you should not be binding it to the grid like that.
 
here is my user table, I excluded the extraction of the added_date field whose type is in timestamp, and the result is error-free. why an error in the added_date field with the type timestamp?
C#:
string sqlRequest = "SELECT id,gender as 'GENDER',first_name as 'FIRST NAME',last_name as 'LAST NAME',email as 'EMAIL',username as 'USERNAME' ,
    password,contact as 'PHONE',address,user_type as 'USER TYPE',added_by FROM tbl_" + table;
 

Attachments

  • 3.png
    3.png
    10.4 KB · Views: 26
A timestamp is not a date.
here is my user table, I excluded the extraction of the added_date field whose type is in timestamp, and the result is error-free. why an error in the added_date field with the type timestamp?

jackie-chan-wait-what-meme.jpg


I read that like :
I did A with B and got no error. So why is there an error with A on B?

That's what you wrote. I suggest if you're going to ask a question, that you put more time and effort into writing one. While I do understand not everyone speaks English, there is no excuse for posting poor questions while the likes of Google Translater exists, and does a substantial job on most translations. There really is no excuse...

Your opening post also doesn't reflect your new question on post 8.
 
You can blame Microsoft for not following the ISO standard (see yellow text below):
timestamp is the synonym for the rowversion data type and is subject to the behavior of data type synonyms. In DDL statements, use rowversion instead of timestamp wherever possible. For more information, see Data Type Synonyms (Transact-SQL).

The Transact-SQL timestamp data type is different from the timestamp data type defined in the ISO standard.

Note
The timestamp syntax is deprecated. This feature is in maintenance mode and may be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

and

rowversion Is a data type that exposes automatically generated, unique binary numbers within a database. rowversion is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The rowversion data type is just an incrementing number and does not preserve a date or a time.

from the MSSQL documentation regarding the rowversion data type.
 
So the root of the issue is that you used an incorrect data type. If you want to record the data and time of creation for a record then you should be using datetime or datetime2. I can't recall what the specific range limit on the former is but we always use the latter.
 
For what its worth, I recall the Datetime type has from 1753 to 9999 as far as i know. Datetime2 has a date range of 01-01-0001 through 31-12-9999

One should remember to be explicit when declaring parameters when using DateTime2 and use SqlDbType.DateTime2 for your date parameter. Bit more found here : datetime2 (Transact-SQL) - SQL Server

Date range is also specified on there too.
 
Back
Top Bottom