forum

Home / DeveloperSection / Forums / how to enter data to sql column(data type is text)

how to enter data to sql column(data type is text)

marcel ethan 1991 18-Dec-2013

I have a project in asp.net, it is an online bus reservation ticket system.

I have error while I try to insert data into my database.

Data which comes from the text box does not match with the data type of my column.

Column name is maplink and datatype is text.

Here is my c# code.

protected void add_Click(object sender, EventArgs e)
 {
         using (SqlConnection con = new SqlConnection("Data Source=JIHAD-PC;Initial Catalog=OBTRS;Integrated Security=True"))
          {
              using (SqlCommand cmd = new SqlCommand())
              {
                  cmd.Connection = con;
                  cmd.CommandText = "INSERT INTO ROUTE
                     ([FROM],[TO],MONDAY,TUESDAY,WEDNESDAY,THURSDAY,
                       FRIDAY,SATURDAY,SUNDAY,FARE,MAPLINK)
                      VALUES ("
                      + DropDownList1.SelectedIndex.ToString() + ","
                      + DropDownList2.SelectedIndex.ToString() + ","
                      + monday + "," + thusday + ","
                      + wednesday + "," + thursay + ","
                      + friday + "," + saturday + ","
                      + sunday + "," + Int32.Parse(fare.ToString()) + ","
                      + maplink.Text + ")";//**here is my error<-----------------------**
                  using (SqlDataAdapter adp = new SqlDataAdapter())
                  {
                      adp.SelectCommand = cmd;
                      DataTable tablo = new DataTable();
                      adp.Fill(tablo);
                  }
              }
          }
    }

Updated on 18-Dec-2013

Can you answer this question?


Answer

1 Answers

Liked By