I have store parent Gridview and child Gridview values into a Datatable. I have used a three tier architecture and want to save this values into the database but when applying the iteration using for loop at one iteration the value is integer so it takes but the other iteration the value is varchar I cannot convert into the varchar because my some values are integer and some varchar.
public string Insertrecord(DataTable dts,string CourseCode,int CourseId)
{
DBHelper.OpenConection();
DBHelper.BeginTransaction();
string query = "";
for (int i = 0; i <= dts.Rows.Count - 1; i++)
{
for (int j = 0; j <= dts.Columns.Count - 1; j++)
{
query = ("Insert into ShortCourses values('" + CourseId + "','" + CourseCode + "','" + dts.Rows[i][j] + "')");
DBHelper.ExecNonQuery(query).ToString();
}
}
DBHelper.CommitTransaction();
DBHelper.CloseConnection();
return query;
}