views:

348

answers:

2

Hi,

I have the following SQL that creates a table and inserts the first row of data without a problem. The default DateTime values are also inserted as expected.

CREATE TABLE Jobs (
[Id]       int PRIMARY KEY IDENTITY(1,1),
[JobName]      nvarchar(256) Default 'SomeName', 
[CreateDate]     DateTime DEFAULT GETDATE(),
[ModifyDate]     DateTime DEFAULT GETDATE(),
[LastOpenDate]     DateTime DEFAULT GETDATE(),
[CreatedByUser]     nvarchar(64) Default 'SomeUser',
[Title]       nvarchar(256) Default 'SomeTitle')
GO
INSERT INTO Jobs (JobName)
VALUES ('NewName')
GO

In Visual Studio 2008 I am using the DataGridView and BindingNavigator controls. When I add a new row the default values are not inserted but nulls are inserted instead. I think this is something to do with the controls but not sure how to get the default values to be used.

Any ideas?

Thanks

A: 

Kindly refer to this link for some good result

http://forums.asp.net/p/1003755/1328318.aspx#1328318

solairaja
Not quite what I was looking for but I achieved what i wanted by creating a SQL statement in the Dataset Designer that would insert a new row with a single "Title" value then the rest of the row would be default values. Couldnt do this using the DataGrid unfortunately. Thanks
Belliez
kindly vote when u accept the answer
solairaja
+1  A: 

You can set the default values for the Datagridview on the DefaultValuesNeeded event

eg:

private void dataGridView1_DefaultValuesNeeded(object sender,
    System.Windows.Forms.DataGridViewRowEventArgs e)
{
    e.Row.Cells["Region"].Value = "WA";
    e.Row.Cells["City"].Value = "Redmond";
    e.Row.Cells["PostalCode"].Value = "98052-6399";
    e.Row.Cells["Region"].Value = "NA";
    e.Row.Cells["Country"].Value = "USA";
    e.Row.Cells["CustomerID"].Value = NewCustomerId();
}