I believe that what you need is the System.DBNull value rather than SqlString.Null.
Jon Stonecash >From: Markus ESSMAYR <[EMAIL PROTECTED]> >Reply-To: dotnet discussion <[EMAIL PROTECTED]> >To: [EMAIL PROTECTED] >Subject: [DOTNET] SqlString.Null? >Date: Fri, 12 Apr 2002 11:05:47 +0200 > >hello! > >i had the following line in my program > >_dataRow["field"] = SqlString.Null; > >_dataRow is of type DataRow and the associated field is of type varchar. > >after saving this change, the column in my database has value "Null" >instead of the 'real' NULL! > >you could then get the row by executing > >SELECT * FROM mytable WHERE field = 'Null' > >and not by > >SELECT * FROM mytable WHERE field IS NULL > >isn't that strange? > > >table: >create table DBTEST (timecode datetime, strfield varchar(100)) >where column timecode is defined as primary key. > >this is my testapp: >using System; >using System.Data; >using System.Data.SqlClient; >using System.Data.SqlTypes; > >namespace DBProblem >{ > public class DBProblem > { > public static int Main(string[] args) > { > // DB connection > SqlConnection Connection = new SqlConnection("Server >=;Database=;User ID=;Password=;Application Name=dbproblem"); > Connection.Open(); > > // Dataset befüllen > SqlCommand Command = new SqlCommand("insert into DBTEST >(timecode, strfield) values (@timecode, @strfield)", Connection); > Command.Parameters.Add(new SqlParameter("@timecode", >SqlDbType.DateTime)); > Command.Parameters["@timecode"].Value = DateTime.Now; > Command.Parameters.Add(new SqlParameter("@strfield", >SqlDbType.VarChar)); > Command.Parameters["@strfield"].Value = SqlString.Null; > Command.ExecuteNonQuery(); > > // row was inserted with column strfield containing NULL > > Command = new SqlCommand("select * from DBTEST", >Connection); > SqlDataAdapter _DataAdapter = new SqlDataAdapter(Command); > SqlCommandBuilder _CommandBuilder = new SqlCommandBuilder >(_DataAdapter); > > DataSet _DataSet = new DataSet(); > > _DataAdapter.Fill(_DataSet, "DBTEST"); > > DataRow _DataRow = _DataSet.Tables["DBTEST"].Rows[0]; > _DataRow["strfield"] = SqlString.Null; > _DataAdapter.Update(_DataSet, "DBTEST"); > > // now, column strfield of first row contains "Null" > > Connection.Close(); > > return 0; > } > } >} >You can read messages from the DOTNET archive, unsubscribe from DOTNET, or >subscribe to other DevelopMentor lists at http://discuss.develop.com. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.