MS Access 데이터베이스의 Double 필드에 null 값을 삽입하려고하는데 할 수 없습니다. 나는 아래 코드를 공유하고있다. 누군가 나를 도울 수 있는가?MS Access 데이터베이스 (매개 변수가 아닌)의 이중 필드에 null을 삽입하십시오.
for (int i = 0; i <= RemovedDuplicateDt.Rows.Count - 1; i++)
{
checkBool = Convert.ToBoolean(RemovedDuplicateDt.Rows[i].ItemArray.GetValue(2).ToString());
if (checkBool)
{
k = -1;
}
else
{
k = 0;
}
if (string.IsNullOrEmpty(RemovedDuplicateDt.Rows[i].ItemArray.GetValue(3).ToString()))
{
scaling = DBNull.Value;
}
else
{
scaling = Convert.ToDouble(RemovedDuplicateDt.Rows[i].ItemArray.GetValue(3).ToString());
}
cmd.CommandText = "INSERT INTO " + "Data VALUES ('" + RemovedDuplicateDt.Rows[i].ItemArray.GetValue(0).ToString() + "' ,"
+ "'" + RemovedDuplicateDt.Rows[i].ItemArray.GetValue(1).ToString() + "' ,"
+ "'" + k + "' ,"
+ "'" + Convert.ToDouble(string.IsNullOrEmpty(RemovedDuplicateDt.Rows[i].ItemArray.GetValue(3).ToString()) ? "0" : RemovedDuplicateDt.Rows[i].ItemArray.GetValue(3)) + "' ,"
+ "'" + Convert.ToDouble(string.IsNullOrEmpty(RemovedDuplicateDt.Rows[i].ItemArray.GetValue(4).ToString()) ? "0" : RemovedDuplicateDt.Rows[i].ItemArray.GetValue(4)) + "' ,"
+ "'" + Convert.ToDouble(string.IsNullOrEmpty(RemovedDuplicateDt.Rows[i].ItemArray.GetValue(5).ToString()) ? "0" : RemovedDuplicateDt.Rows[i].ItemArray.GetValue(5)) + "' ,"
+ "'" + RemovedDuplicateDt.Rows[i].ItemArray.GetValue(6).ToString() + "' ,"
+ "'" + RemovedDuplicateDt.Rows[i].ItemArray.GetValue(7).ToString() + "' ,"
+ "'" + Convert.ToInt16(string.IsNullOrEmpty(RemovedDuplicateDt.Rows[i].ItemArray.GetValue(8).ToString()) ? "0" : RemovedDuplicateDt.Rows[i].ItemArray.GetValue(8)) + "' ,"
+ "'" + RemovedDuplicateDt.Rows[i].ItemArray.GetValue(9).ToString() + "' ,"
+ "'" + RemovedDuplicateDt.Rows[i].ItemArray.GetValue(10).ToString() + "' ,"
+ "'" + RemovedDuplicateDt.Rows[i].ItemArray.GetValue(11).ToString() + "' ,"
+ "'" + Convert.ToInt32(string.IsNullOrEmpty(RemovedDuplicateDt.Rows[i].ItemArray.GetValue(12).ToString()) ? "0" : RemovedDuplicateDt.Rows[i].ItemArray.GetValue(12)) + "' ,"
+ "'" + Convert.ToInt32(string.IsNullOrEmpty(RemovedDuplicateDt.Rows[i].ItemArray.GetValue(13).ToString()) ? "0" : RemovedDuplicateDt.Rows[i].ItemArray.GetValue(13)) + "' ,"
+ "'" + RemovedDuplicateDt.Rows[i].ItemArray.GetValue(14).ToString() + "' ,"
+ "'" + RemovedDuplicateDt.Rows[i].ItemArray.GetValue(15).ToString() + "' ,"
+ "'" + RemovedDuplicateDt.Rows[i].ItemArray.GetValue(16).ToString() + "' ,"
+ "'" + RemovedDuplicateDt.Rows[i].ItemArray.GetValue(17).ToString() + "' ,"
+ "'" + Convert.ToInt32(string.IsNullOrEmpty(RemovedDuplicateDt.Rows[i].ItemArray.GetValue(18).ToString()) ? "0" : RemovedDuplicateDt.Rows[i].ItemArray.GetValue(18)) + "')";
cmd.ExecuteNonQuery();
}
이 코드는 작동하지만 데이터베이스에서 "0"을보고 싶지 않습니다. null (공백)을보고 싶습니다.
Convert.ToDouble (null)하려고 할 때 오류가 발생합니다. DBNull.Value에 "DB missmatch criteria"오류가 발생했습니다.
나는이 코드를 사용하여 데이터베이스에 null을 삽입하는 방법이 필요하다.
사용하고 싶지 않습니다.
cmd.Parameters.AddWithValue("Scaling", Double.TryParse(RemovedDuplicateDt.Rows[i].ItemArray.GetValue(3).ToString(), out result) ? (object)result : DBNull.Value);,
그 사용량이 너무 느려 때문에,
그리고 내 데이터베이스 설계가 같다;나는 당신의 응답을 기다리고, 들으!
'더블 셀'은'0' 또는'null'을 포함하는'RemovedDuplicateDt'에서? –
RemovedDuplicateDt에서 문자열 형식의 모든 셀 및이 셀이 null입니다 – bakin