samsmithnz Posted March 25, 2004 Posted March 25, 2004 I'm trying to add a row to my dataset programattically, but I can't seem to add a null value to a datetime in the row. objDR = dsReviewers.Tables("Reviewers").NewRow objDR.Item("reviewer_notification_date") = nothing I thought that was the equivalent, but it doesn't work, if I isdbnull it further down the page, I get this error: System.ArgumentException: Cannot set Column 'reviewer_notification_date' to be null. Please use DBNull instead. at System.Data.DataRow.set_Item(DataColumn column, Object value) at System.Data.DataRow.set_Item(String columnName, Object value) at APWorkflow.Reviewers.btnAdd_Click(Object sender, ImageClickEventArgs e) in \\corpdev1\wwwroot$\APWorkflow\Reviewers.aspx.vb:line 159 what am I doing wrong, It seems like I've already tryed everything!@@!@ Quote Thanks Sam http://www.samsmith.co.nz
Aitmanga Posted March 25, 2004 Posted March 25, 2004 You could try: objDR.Item("reviewer_notification_date")=System.DBNull.Value Quote
samsmithnz Posted March 25, 2004 Author Posted March 25, 2004 That seemed to work, but then later when I saved the dataset to the viewstate and reloaded it, the column with the null value was dropped off. Any other suggestions...? Quote Thanks Sam http://www.samsmith.co.nz
*Experts* Nerseus Posted March 25, 2004 *Experts* Posted March 25, 2004 Do you mean you saved the DataSet as XML and reloaded it? Make sure you specifiy to save the schema. DBNull values are represented in XML by NOT being there :) -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
samsmithnz Posted March 25, 2004 Author Posted March 25, 2004 Yeh I've just been experimenting with that. I think I know a bit more of the problem (but its still a problem). What I'm trying to do is do an initial read from the database, and read my dataset up to my asp.net page where its bound to a datagrid. I then save the dataset away in the viewstate, and retrieve it whenever I have to add or delete a row. When the user presses the save button it goes back to the database. This all works fine until I read from the database and there are NO rows. objDataRow = dsReviewers.Tables("Reviewers").NewRow This fails as it doesn't know what the schema was. So I added these lines to the database call: 'Fill the dataset from the dataadapter objDataSet = New DataSet objDataSet.Tables.Add("Reviewers") objSQLDA.FillSchema(objDataSet.Tables("Reviewers"), SchemaType.Mapped) objSQLDA.Fill(objDataSet, "Reviewers") Now I create the table and populate if I need too + I'm getting the schema, so now it should know what sort of row to add when I call NewRow right? Well not yet. What happens is when I step through the code it all looks right until I save it to my viewstate. When I read it out, my empty table is GONE! What's wrong? Quote Thanks Sam http://www.samsmith.co.nz
samsmithnz Posted March 26, 2004 Author Posted March 26, 2004 *Bump* I'm sorry I hate doing this, but its friday and deadlines are upon me! :eek: :eek: :eek: Quote Thanks Sam http://www.samsmith.co.nz
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.