Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13-11-2009
Member
 
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 = tbPictures.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 = tbPictures.Text;
gives
Quote:
Can not implicitly convert type 'string' to 'byte []'
Code:
newShelterRow.DateCreated = dtpDateCreated.Text;
gives
Quote:
Can not implicitly convert type 'string' to 'System.DateTime'
Code:
newShelterRow.DateModified = dtpDateModified.Text;
gives
Quote:
Can not implicitly convert type 'string' to 'System.DateTime'
Reply With Quote
  #2  
Old 13-11-2009
Member
 
Join Date: May 2008
Posts: 2,383
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 = tbPictures.Text;
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 13-11-2009
Member
 
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 = tbPictures.Image ;
But I have the following error:
Quote:
'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*?)
Reply With Quote
  #4  
Old 13-11-2009
Member
 
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
Reply With Quote
  #5  
Old 13-11-2009
Member
 
Join Date: May 2008
Posts: 2,383
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...
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #6  
Old 13-11-2009
Member
 
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 = pbPicture.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:
Quote:
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 10:53 PM.