0

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()
            {
                InitializeComponent();
            }
            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);

                conn.Open();

                SqlDataReader reader = cmd.ExecuteReader();

                while(reader.Read())
                {

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


            }
2
Contributors
6
Replies
13
Views
2 Years
Discussion Span
Last Post by Praveen_10
0

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.

0

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

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.