11
Answers

Please help me for changing data table row value from dictionary

Cenk Isik

Cenk Isik

12y
5k
1
I have a dictionary I want to read this as for that my data table row value. I'm reading dictionary and data table row value but i cant change row value that coming dictionary value 

exception is =Input string was not in a correct format.Couldn't store <Eskisehir> in IL Column.  Expected type is Int16.

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;
    }
Answers (11)