Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
INSERT INTO TripSheet2(TripNumber,State,OdometerStart,OdometerEnd,Distance
,NonTaxableDistance,TaxableDistance,FuelPurchased,GalLit,Driver,TripID) VALUES"

C#
            if (item.Contains(","))
            {
                splitItems = item.Split(",".ToCharArray());
                sb.Clear();


sb.AppendFormat("{0}('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',{11}); ", sqlStatement, splitItems[0], splitItems[1], splitItems[2], splitItems[3], splitItems[4], splitItems[5], splitItems[6], splitItems[7], splitItems[8], splitItems[9],Convert.ToInt32(Session["tripID"]));

Upper Append Format is wrong .....................

plz help me
Thanks in Advance
Posted
Updated 26-Jul-12 4:01am
v2
Comments
StianSandberg 26-Jul-12 3:29am    
What datatypes are your sql-tables columns? Sounds like you are trying to insert a string to a numeric column or something..
[no name] 26-Jul-12 7:39am    
Your problem is probably Convert.ToInt32(Session["tripID"])
Nandakishore G N 27-Jul-12 1:11am    
Hav u checked whether session has values or not?

Here is what I would do. Set a break point in you code where you can inspect the content of the stringbuilder. Copy the content of the stringbuilder to SSMS (assuming it is sql server) and try and execute the string.

When it fails fiddle with it till it works and then repeat the process in your code. It is called debugging!
 
Share this answer
 
Comments
shuresh 26-Jul-12 4:32am    
I already Debugged it...IN this part only i got error ...INPUT STRING WAS NOT IN CORRECT FORMAT

sb.AppendFormat("{0}('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',{11}); ", sqlStatement, splitItems[0], splitItems[1], splitItems[2], splitItems[3], splitItems[4], splitItems[5], splitItems[6], splitItems[7], splitItems[8], splitItems[9],Convert.ToInt32(Session["tripID"]));
Some hints:
- use a parameterized query.
- What is "item" - a string? Better create a class with appropriate properties!
- Are you sure that all the commas in your string are all used for delimitng its contents? What about a driver name of "Doe, John"?
 
Share this answer
 
Convert.ToInt32(Session["tripID"])

I'd look in the database first to verify the tripID field is set to Integer and not a String. If that is ok, then move on to the next step:

Try applying this value to a variable to see if it throws an error on that line. If so, you may want to review your data values to verify that tripID contains only Integers.

Create this variable
Int tripid = Convert.ToInt32(Session["tripID"])

Run/Test to see if this line throws an error. If it does, you have an issue with this value.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900