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);
}
}
}
}
Anonymous User
18-Dec-2013You should REALLY use parametrized queries - ALWAYS, no exceptions. Those are safe against SQL injection attacks, and they're often faster, too.