我遇到了一个奇怪的子字符串问题。显然,由于某种奇怪的原因,我得到的字符串无法转换为 Int32。当我尝试这样做时收到的错误消息是“输入字符串的格式不正确”。因此,我也无法将这些值插入数据库。
这是代码...
string width = GetMetadata(filename, 162); //returns "1280 pixels"
string height = GetMetadata(filename, 164); //returns "700 pixels"
width = width.Substring(0, width.IndexOf(' ')); //returns "1280"
height = height.Substring(0, height.IndexOf(' ')); //returns "700"
//test: "System.Convert.ToInt32(width)" will fail, giving error "input string was not in correct format"
//doing the above on "width" yields the same result
//fails, giving error "no such column: 1280" (underlying database is sqlite)
Database.NonQuery("INSERT INTO image VALUES (" + fileid + ", " + width + ", " + height + ")");