上のゼロの代わりにヌルを返すようにシート名としてExcelファイルに関する情報を格納することFlatFileSetting
と呼ばれ、コラムなどをカウントオブジェクトのプロパティは、私はデータベースのテーブルを持っているWebフォーム
ユーザーが使用して、このテーブル内のデータの個々の行を編集することができます.NET Webアプリケーションのフォーム。フォームは、FlatFileSetting object
から値を取得することによって設定されます。
これは正常に動作し、テキストボックスにはデータがある場合に予想どおりにデータが格納されますが、データベースに整数フィールドのNULL値が含まれていると、関連するテキストボックスには空白ではなく0が表示されます。オブジェクト
public class FlatFileSetting
{
public int ColumnCount { get; set; }
public string SheetName { get; set; }
public void GetRecord(int FlatFileSettingId)
{
string myConnectionString = "Foo";
var myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[myConnectionString].ConnectionString);
SqlCommand myCommand = myConnection.CreateCommand();
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "[dbo].[getFlatFileSetting]";
myCommand.Parameters.AddWithValue("@FlatFileSettingId", FlatFileSettingId);
using (myConnection)
using (myCommand)
{
if (myReader["ColumnCount"] != DBNull.Value)
{
this.ColumnCount = Int32.Parse(myReader["ColumnCount"].ToString());
}
if (myReader["SheetName"] != DBNull.Value)
{
this.SheetName = myReader["SheetName"].ToString();
}
}
}
}
をFlatFileSetting
私は理由が!= DBNull.Value
をどうするだろう知っているが、私はそれが含まれていない場合、私はInput String Not in the Correct format
エラーを取得します。
私はオブジェクトプロパティのデータ型をすべて文字列に変更することでこれを解決できることも知っていますが、同じデータ型として保持する必要があります。
すべてのヘルプは大