exception is =Input string was not in a correct format.Couldn't store
I fill data table from database and IL column type smallint i dont want to change column type nvarchar or anything else . How i can solve this problem .
My Code Here;
public DataTable getData(string komut)
{
DataTable dt = new DataTable();
cnn = connect.GetConnection();
sorgu = komut;
cmd = new SqlCommand(sorgu, cnn);
adap = new SqlDataAdapter(cmd);
adap.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Columns["IL"].ColumnName == "IL")
{
string tmpSehir;
iller.TryGetValue(dt.Rows[i]["IL"].ToString(), out tmpSehir);
dt.Rows[i]["IL"] = tmpSehir;
}
}
return dt;
}

VulpesRank #55 · 29.2K reputationPosted Jul 30, 2012, 12:47 AM EDT
Cenk Isik42 reputationPosted Jul 30, 2012, 1:00 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 30, 2012, 1:05 AM EDT
Possible reasons include it being an empty string, containing a decimal point or thousand separator or being out of range.
I'd try printing out some values of tmpSehir to see what it actually contains.
Cenk Isik42 reputationPosted Jul 30, 2012, 2:19 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 30, 2012, 3:11 AM EDT
Cenk Isik42 reputationPosted Jul 30, 2012, 3:37 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 30, 2012, 5:10 AM EDT
There's no way they can converted to integers which is why Int16.TryParse is returning zero for them.
Cenk Isik42 reputationPosted Jul 30, 2012, 5:40 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 30, 2012, 5:49 AM EDT
Another possibility would be store your city names using an integer code - if there are only a limited number of them you could define a Dictionary
Cenk Isik42 reputationPosted Jul 30, 2012, 5:54 AM EDT
Cenk Isik42 reputationPosted Aug 2, 2012, 12:34 AM EDT