將字符串從數據庫轉換爲整數時出現問題。將數據庫中的值轉換爲整數時輸入字符串格式不正確
當我看看當地人,那個變量顯示的值,但通知仍然說有什麼問題。任何人都可以幫助我?
OleDbConnection kon = new OleDbConnection(koneksi);
OleDbCommand command1 = kon.CreateCommand();
kon.Open();
string selectkoordgaris = "select * from koordinatgaris where namakamera = '" + PilihKameraComboBox.Text + "'";
command1.CommandText = selectkoordgaris;
OleDbDataReader bacakoordgaris = command1.ExecuteReader();
while (bacakoordgaris.Read())
{
var templateGaris = Directory.GetFiles(@"D:\Dokumen\Alfon\TA Alfon\CobaFitur\Template\Garis\" + bacakoord["namakamera"].ToString());
foreach (var fileGaris in templateGaris)
{
counterbanyakgaris++;
Image<Bgr, byte> garis = new Image<Bgr, byte>(fileGaris);
for (cntgaris = 0; cntgaris < banyakgaris; cntgaris++)
{
int x1garis = int.Parse(bacakoordgaris["x" + ((cntgaris * 4) + 1) + "garis"].ToString()); //here the error. It says Input string was not in a correct format
int x2garis = int.Parse(bacakoordgaris["x" + ((cntgaris * 4) + 2) + "garis"].ToString());
int y1garis = int.Parse(bacakoordgaris["y" + ((cntgaris * 4) + 1) + "garis"].ToString());
int y2garis = int.Parse(bacakoordgaris["y" + ((cntgaris * 4) + 2) + "garis"].ToString());
int y3garis = int.Parse(bacakoordgaris["y" + ((cntgaris * 4) + 3) + "garis"].ToString());
int gariswidth = x2garis - x1garis;
int garisheight = y3garis - y2garis;
}
}
}
數據庫表中的x和y列是否存在?從表中的列中獲取數據的正確方法是bacakoordgaris [「columnName」]。ToString() – Kami
您是否評估過'bacakoordgaris [「x」+((cntgaris * 4)+ 1)+「garis」]以查看它返回什麼? – lintmouse
是@Kami。 x和y是我DB表中的列。所以在這裏,我想從每個x和y列中獲取值取決於cntgaris的值。當我的cntgaris爲0時,我的x1garis值從x1garis列中獲得,x2garis從x2garis等中獲得。當我的cntgaris爲1時,我的x1garis值從x5garis獲得,我的x2garis從x6garis等獲得 –