Cenk Isik

Cenk Isik

  • NA
  • 44
  • 26.2k

Please help me for changing data table row value from dictionary

Jul 30 2012 3:45 AM
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)