Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!@@!@

  • *Experts*
Posted

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

"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
Posted

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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...