---
title: "how to enter data to sql column(data type is text)"  
description: "how to enter data to sql column(data type is text)"  
author: "marcel ethan"  
published: 2013-12-18  
updated: 2013-12-18  
canonical: https://www.mindstick.com/forum/1810/how-to-enter-data-to-sql-column-data-type-is-text  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# how to enter data to sql column(data type is text)

I have a [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) in [asp.net](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder), it is an [online](https://www.mindstick.com/articles/13083/benefits-of-students-who-can-get-online-assignment) bus [reservation](https://answers.mindstick.com/qa/50296/what-is-reservation-_) ticket system.

I have error while I try to [insert data](https://www.mindstick.com/forum/33964/insert-data-in-datagridview-from-text-box-c-sharp) into my database.

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

[Column name](https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid) is maplink and [datatype](https://www.mindstick.com/forum/160266/explain-the-datatype-data-annotation-and-its-significance-in-data-entry-and-display) is text.

**Here is my [c# code](https://www.mindstick.com/forum/403/how-to-export-data-in-excel-file-from-sql-server-using-c-sharp-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);                  }              }          }    }
```

## Replies

### Reply by Anonymous User

Hi Marcel,

You should REALLY use parametrized queries - ALWAYS, no exceptions. Those are safe against SQL injection attacks, and they're often faster, too.

```
protected void add_Click(object sender, EventArgs e){    string insertStmt = "INSERT INTO dbo.ROUTE([FROM], [TO], MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY,
SUNDAY, FARE, MAPLINK) " +                      
"VALUES(@From, @To, @Monday, @Tuesday, @Wednesday, @Thursday,
@Friday, @Saturday, @Sunday, @Fare, @Maplink)";    using
(SqlConnection con = new SqlConnection("Data Source=JIHAD-PC;Initial Catalog=OBTRS;Integrated Security=True"))    using (SqlCommand cmd = new SqlCommand(insertStmt, con))    {        // fill the parameters       
cmd.Parameters.Add("@From", SqlDbType.Varchar, 50).Value =DropDownList1.SelectedIndex.ToString();       
cmd.Parameters.Add("@To", SqlDbType.Varchar, 50).Value =DropDownList2.SelectedIndex.ToString();       
cmd.Parameters.Add("@Monday", SqlDbType.Int).Value = monday;       
cmd.Parameters.Add("@Tuesday", SqlDbType.Int).Value = tuesday;       
cmd.Parameters.Add("@Wednesday", SqlDbType.Int).Value =wednesday;       
cmd.Parameters.Add("@Thursday", SqlDbType.Int).Value =thursday;        cmd.Parameters.Add("@Friday",
SqlDbType.Int).Value = friday;       
cmd.Parameters.Add("@Saturday", SqlDbType.Int).Value =saturday;       
cmd.Parameters.Add("@Sunday", SqlDbType.Int).Value = sunday;       
cmd.Parameters.Add("@Fare", SqlDbType.Int).Value = fare;       
cmd.Parameters.Add("@Maplink", SqlDbType.VarChar, 100).Value =maplink.Text;        // open connection, execute INSERT command, close connection        con.Open();       
cmd.ExecuteNonQuery();        con.Close();    }}
```


---

Original Source: https://www.mindstick.com/forum/1810/how-to-enter-data-to-sql-column-data-type-is-text

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
