要做个SQL语句的拼接,我先用了个循环,可是当记录为null的时候有异常,无法判断是哪种数据类型,但我已经找到解决的方法,领导不同意,让我直接手动拼,(C#代码)
for (int i = 0; i < ReadData.FieldCount; i++)
                    {
                        if ("System.String" == ReadData.GetValue(i).GetType().ToString())
                        {
                            try
                            {
                                strField = "'" + ReadData.GetString(i) + "'";
                            }
                            catch (System.Exception)
                            {
                                strField = "''";
                            }
                        }else if ("System.Decimal" == ReadData.GetValue(i).GetType().ToString())
                        {
                            try
                            {
                                strField = ReadData.GetString(i);
                            }
                            catch (System.Exception)
                            {
                             strField = "0";
                            }
                        }
                        else if ("System.DateTime" == ReadData.GetValue(i).GetType().ToString())
                        {
                            try
                            {
                                strField = "'" + ReadData.GetString(i) + "'";
                            }
                            catch (System.Exception)
                            {
                                strField = "'1900-01-01'";
                            }
                        }
                        else
                        {
                            System.Exception ex = new Exception();
                            //ex.Message = "未知的数据类型";
                            throw ex;
                        }                        strValue = strValue + strField + ", ";                    }
                    strValue = strValue.Substring(0, strValue.Length - 2);我终于知道某些人的十万行代码是怎么来的了,这是我不愿做的,差点恶心死自己。
try
{
strField = "'" + ReadData.GetString(0) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(1) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(2) + "'";
}
catch (System.Exception)
{
strField = "'1900-01-01'";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(3) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(4) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(5) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(6) + "'";
}
catch (System.Exception)
{
strField = "'1900-01-01'";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(7) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(8) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(9) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(10) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(11) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(12) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = ReadData.GetString(13);
}
catch (System.Exception)
{
strField = "0";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(14) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(15) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = ReadData.GetString(16);
}
catch (System.Exception)
{
strField = "0";
}strValue = strValue + strField + ", ";try
{
strField = ReadData.GetString(17);
}
catch (System.Exception)
{
strField = "0";
}strValue = strValue + strField + ", ";try
{
strField = ReadData.GetString(18);
}
catch (System.Exception)
{
strField = "0";
}strValue = strValue + strField + ", ";try
{
strField = ReadData.GetString(19);
}
catch (System.Exception)
{
strField = "0";
}strValue = strValue + strField + ", ";try
{
strField = ReadData.GetString(20);
}
catch (System.Exception)
{
strField = "0";
}strValue = strValue + strField + ", ";try
{
strField = ReadData.GetString(21);
}
catch (System.Exception)
{
strField = "0";
}strValue = strValue + strField + ", ";try
{
strField = ReadData.GetString(22);
}
catch (System.Exception)
{
strField = "0";
}strValue = strValue + strField + ", ";try
{
strField = ReadData.GetString(23);
}
catch (System.Exception)
{
strField = "0";
}strValue = strValue + strField + ", ";try
{
strField = ReadData.GetString(24);
}
catch (System.Exception)
{
strField = "0";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(25) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(26) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(27) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(28) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(29) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(30) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(31) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(32) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(33) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(34) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(35) + "'";
}
catch (System.Exception)
{
strField = "'1900-01-01'";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(36) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(37) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(38) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(39) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(40) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(41) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(42) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(43) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField + ", ";try
{
strField = "'" + ReadData.GetString(44) + "'";
}
catch (System.Exception)
{
strField = "''";
}strValue = strValue + strField;