Results 1 to 6 of 6

Thread: Lots of errors when inserting data into table

  1. #1
    Join Date
    Nov 2009
    Posts
    37

    Lots of errors when inserting data into table

    I want to insert data into my table Shelter from a form (with TextBox, DateTimePicker, Image, comboBox ...). However, my code returns me different errors.

    Description of my table Shelter
    Code:
    Code int 4 Primary key
    Category nvarchar 50
    Name nvarchar 50 
    NbOfAdult nvarchar 2 
    NbOfKid nvarchar 2
    RateOfTVA nvarchar 10 
    PriceTTC int 4
    Picture image
    DateCreated datetime
    DateModified datetime
    ModifiedBy nvarchar 50
    Here is my code:
    Code:
    private void btnOK_Click(object sender, EventArgs e)
            {
                dbShelterDataSet1.ShelterRow newShelterRow = dbShelterDataSet1.Shelter.NewShelterRow();
     
                newShelterRow.Code = Int32.Parse(tbReference.Text);
                newShelterRow.Category = cbCategory.Text;
                newShelterRow.Name = tbNameShelter.Text;
                newShelterRow.NbOfAdult = Int32.Parse(mtbNbOfAdult.Text);
                newShelterRow.NbOfKid = Int32.Parse(mtbNbOfKid.Text);
                newShelterRow.RateOfTVA = Int32.Parse(cbRateOfTVA.Text);
                newShelterRow.PriceTTC = Int32.Parse(tbLowSeasonWeekPriceTTC.Text);
                newShelterRow.Picture = t***ctures.Text;
                newShelterRow.DateCreated = dtpDateCreated.Text;
                newShelterRow.DateModified = dtpDateModified.Text;
                newShelterRow.ModifiedBy = cbModifiedBy.Text;
     
                dbShelterDataSet1.Shelter.AddShelterRow(newShelterRow);
                try
                {
                    shelterTableAdapter.Update(dbShelterDataSet1.Shelter);
                }
                catch (SqlCeException exception)
                {
                    MessageBox.Show("Error :\n" + exception.Message, "Error");
                }
            }
    I have the following errors:

    Code:
    newShelterRow.Picture = t***ctures.Text;
    gives
    Can not implicitly convert type 'string' to 'byte []'
    Code:
    newShelterRow.DateCreated = dtpDateCreated.Text;
    gives
    Can not implicitly convert type 'string' to 'System.DateTime'
    Code:
    newShelterRow.DateModified = dtpDateModified.Text;
    gives
    Can not implicitly convert type 'string' to 'System.DateTime'

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: Lots of errors when inserting data into table

    I have not read everything already but this concerns me

    Not you?

    Code:
    Picture image
    and you do

    Code:
    newShelterRow.Picture = t***ctures.Text;

  3. #3
    Join Date
    Nov 2009
    Posts
    37

    Re: Lots of errors when inserting data into table

    Picture is the field name of my table Shelter. Picture type is an image. I put her, because when you create a table in my dbShelter.sdf. It offers the type: image.

    Because I try to put the following code:
    Code:
    newShelterRow.Picture = t***ctures.Image ;
    But I have the following error:
    'System.Windows.Forms.TextBox' does not contain a definition for 'image' and no extension method 'Image' accepting a first argument of type 'System.Windows.Forms.TextBox' has been found (a directive Using or an assembly reference is missing*?)

  4. #4
    Join Date
    Nov 2008
    Posts
    1,054

    Re: Lots of errors when inserting data into table

    I have the impression that you have a learning wizard, mixing all the jars you have on hand without knowing what they contain. A TextBox is not used to contain an image. A DateTime that is not text.

    Errors will be clear to me: you must convert your variables as you can tell him a picture object is equal to the text. I believe you must use the CONVERT function to change your type

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: Lots of errors when inserting data into table

    I do not think the Convert method converts the text to image or vice versa

    Before trying to convert I would first type of inventory in the database to use a form provided with controls that may be pertinent

    For the picture its an image

    For DateTime they are DateTimePicker.Value etc...

  6. #6
    Join Date
    Nov 2009
    Posts
    37

    Re: Lots of errors when inserting data into table

    Thank you for your responses. I think I managed to DateTimePicker. However I have one exception:

    Here is my new code:
    Code:
    private void btnOK_Click(object sender, EventArgs e)
            {
                dbShelterDataSet1.ShelterRow newShelterRow = dbShelterDataSet1.Shelter.NewShelterRow();
                newShelterRow.Category = cbCategory.Text;
                newShelterRow.Name = tbNameShelter.Text;
                newShelterRow.NbOfAdult = int.Parse(mtbNbOfAdult.Text);
                newShelterRow.NbOfKid = int.Parse(mtbNbOfKid.Text);
                newShelterRow.RateOfTVA = Int32.Parse(cbRateOfTVA.Text);
                newShelterRow.PriceTTC = int.Parse(tbLowSeasonWeekPriceTTC.Text);
                //newShelterRow.Picture = p***cture.Image;
                newShelterRow.DateCreated = dtpDateCreated.Value;
                newShelterRow.DateModified = dtpDateModified.Value;
                newShelterRow.ModifiedBy = cbModifiedBy.Text;
     
                dbShelterDataSet1.Shelter.AddShelterRow(newShelterRow);
                try
                {
                    shelterTableAdapter.Update(dbShelterDataSet1.Shelter);
                }
                catch (SqlCeException exception)
                {
                    MessageBox.Show("Error :\n" + exception.Message, "Error");
                }
            }
    The exception is the following:
    The exception NoNullAllowed was not handled.
    The Code column is the primary key of my table Shelter. So, how do I make an autoincrement column of my code? The column 'code' does not allow nulls.

Similar Threads

  1. In iOS 6, new Map app will consume lots of data
    By klinsmann in forum Portable Devices
    Replies: 4
    Last Post: 12-07-2012, 02:05 PM
  2. Inserting a Row at the end of a Table in Microsoft Excel
    By Ramanujan in forum MS Office Support
    Replies: 2
    Last Post: 01-02-2012, 02:06 PM
  3. Problem while inserting data in MS Access
    By Cheng-Gong in forum Windows Software
    Replies: 6
    Last Post: 28-02-2011, 08:27 PM
  4. Inserting bulk data using Java
    By Halyn in forum Software Development
    Replies: 4
    Last Post: 09-11-2009, 05:41 PM
  5. How to copy one table data into another table directly?
    By ComPaCt in forum Software Development
    Replies: 3
    Last Post: 22-09-2009, 03:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,577,166.82144 seconds with 17 queries