I have not completed the code ...but why am i getting error inside while loop saying cannot convert string to int...when i am not converting string to int

namespace book
        public partial class car : Form
            public car()
            void FilCombo()
                SqlConnection conn = new SqlConnection("Data Source=PRAVEEN\\SQLEXPRESS;Initial Catalog=travelbooking;Integrated Security=True");

                SqlCommand cmd = new SqlCommand("select *from Carss travelbooking.Carss", conn);


                SqlDataReader reader = cmd.ExecuteReader();


                    string sname = reader.GetString("CarName");


Recommended Answers

All 6 Replies

Please help me

It is because getString() accepts an integer, not a string. You pass in the zero-based reference for the column you want. Instead of passing in "CarName" pass in the position of that column.

Thankyou...but is there an alternate for getstring for directly using the column name

okay if i give column number i am getting an exception "Incorrect syntax near '.'."

Thats coming from your SQL statement. Which table are you trying to select from because it looks like you are referring to two.

hey i got it solved....thanks ....select statement was totally wrong :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.