Default values in SQL and ADO.NET

  • Thread starter Thread starter michael
  • Start date Start date
M

michael

I'm having problems getting default column values(which I
set by design in a table in SQL Server) correctly
updating a DataSet after a new row is entered into the
DataSet(except the column in question) and the
DataAdapter.Update called.

When I set up my DataTable in the DataSet(with a
DataAdapter.FillSchema), shouldn't a column's
DefaultValue be set to the default value specified in the
SQL table?

Michael
 
Are you setting the respective column's default value or are you expecting
it to come back as such from the DB? I can't say for sure that there's no
way to get it back from the table schema itself but I was under the
impression that you need to set values like Default, AutoIncrement etc once
you have the data back, although from what I understand, that isn't
necessarily the case if you have a STronglyTyped DataSet...

This link here
http://authors.aspalliance.com/aspxtreme/sys/Data/datacolumnclassdefaultvalue.aspx
shows you how to do it....but If there's a way to get it straight from the
DB using a standard dataset, I'd be intersted in learning how to do it.

HTH,

Bill
 
Thank for William's reply.

Hi Michael,

I'd like to offer some futher information on this issue. The default value
of the column in SQL server will take effect only when you don't specify
any value to that column when updating or inserting data into the table.
Even if we specify a null value to it, the default value will not take
effect.

So please try to take William's suggestion to set the defaultvalue property
of the column. Or if you're using a stored procedure as a InsertCommand or
UpdateCommand, you can set the default value in the argument list of the
stored procedure.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "William Ryan" <[email protected]>
| References: <[email protected]>
| Subject: Re: Default values in SQL and ADO.NET
| Date: Sat, 18 Oct 2003 19:26:49 -0400
| Lines: 33
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: pcp05123303pcs.martnz01.ga.comcast.net 68.47.54.220
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:63970
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Are you setting the respective column's default value or are you
expecting
| it to come back as such from the DB? I can't say for sure that there's no
| way to get it back from the table schema itself but I was under the
| impression that you need to set values like Default, AutoIncrement etc
once
| you have the data back, although from what I understand, that isn't
| necessarily the case if you have a STronglyTyped DataSet...
|
| This link here
|
http://authors.aspalliance.com/aspxtreme/sys/Data/datacolumnclassdefaultvalu
e.aspx
| shows you how to do it....but If there's a way to get it straight from the
| DB using a standard dataset, I'd be intersted in learning how to do it.
|
| HTH,
|
| Bill
| | > I'm having problems getting default column values(which I
| > set by design in a table in SQL Server) correctly
| > updating a DataSet after a new row is entered into the
| > DataSet(except the column in question) and the
| > DataAdapter.Update called.
| >
| > When I set up my DataTable in the DataSet(with a
| > DataAdapter.FillSchema), shouldn't a column's
| > DefaultValue be set to the default value specified in the
| > SQL table?
| >
| > Michael
| >
| >
|
|
|
 
Thanks. Too bad the Default from the SQL table is not
automatically loaded into the defaultvalue for the column
during a .fillschema

Michael
-----Original Message-----
Thank for William's reply.

Hi Michael,

I'd like to offer some futher information on this issue. The default value
of the column in SQL server will take effect only when you don't specify
any value to that column when updating or inserting data into the table.
Even if we specify a null value to it, the default value will not take
effect.

So please try to take William's suggestion to set the defaultvalue property
of the column. Or if you're using a stored procedure as a InsertCommand or
UpdateCommand, you can set the default value in the argument list of the
stored procedure.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "William Ryan" <[email protected]>
| References: <[email protected]>
| Subject: Re: Default values in SQL and ADO.NET
| Date: Sat, 18 Oct 2003 19:26:49 -0400
| Lines: 33
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host:
pcp05123303pcs.martnz01.ga.comcast.net 68.47.54.220
 
Hi Michael,

Thank you for your feedback. I'll forward it through an appropriate channel.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "hockstein" <[email protected]>
| Sender: "hockstein" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Default values in SQL and ADO.NET
| Date: Mon, 20 Oct 2003 12:04:13 -0700
| Lines: 112
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOXPPOXidUOx78ORFOvoqojWXtzCQ==
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:64078
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Thanks. Too bad the Default from the SQL table is not
| automatically loaded into the defaultvalue for the column
| during a .fillschema
|
| Michael
|
| >-----Original Message-----
| >Thank for William's reply.
| >
| >Hi Michael,
| >
| >I'd like to offer some futher information on this issue.
| The default value
| >of the column in SQL server will take effect only when
| you don't specify
| >any value to that column when updating or inserting data
| into the table.
| >Even if we specify a null value to it, the default value
| will not take
| >effect.
| >
| >So please try to take William's suggestion to set the
| defaultvalue property
| >of the column. Or if you're using a stored procedure as
| a InsertCommand or
| >UpdateCommand, you can set the default value in the
| argument list of the
| >stored procedure.
| >
| >If anything is unclear, please feel free to reply to the
| post.
| >
| >Kevin Yu
| >=======
| >"This posting is provided "AS IS" with no warranties,
| and confers no
| >rights."
| >
| >--------------------
| >| From: "William Ryan" <[email protected]>
| >| References: <[email protected]>
| >| Subject: Re: Default values in SQL and ADO.NET
| >| Date: Sat, 18 Oct 2003 19:26:49 -0400
| >| Lines: 33
| >| X-Priority: 3
| >| X-MSMail-Priority: Normal
| >| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| >| X-MimeOLE: Produced By Microsoft MimeOLE
| V6.00.2800.1165
| >| Message-ID: <[email protected]>
| >| Newsgroups: microsoft.public.dotnet.framework.adonet
| >| NNTP-Posting-Host:
| pcp05123303pcs.martnz01.ga.comcast.net 68.47.54.220
| >| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!
| tk2msftngp13.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.framework.adonet:63970
| >| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
| >|
| >| Are you setting the respective column's default value
| or are you
| >expecting
| >| it to come back as such from the DB? I can't say for
| sure that there's no
| >| way to get it back from the table schema itself but I
| was under the
| >| impression that you need to set values like Default,
| AutoIncrement etc
| >once
| >| you have the data back, although from what I
| understand, that isn't
| >| necessarily the case if you have a STronglyTyped
| DataSet...
| >|
| >| This link here
| >|
| >http://authors.aspalliance.com/aspxtreme/sys/Data/datacol
| umnclassdefaultvalu
| >e.aspx
| >| shows you how to do it....but If there's a way to get
| it straight from the
| >| DB using a standard dataset, I'd be intersted in
| learning how to do it.
| >|
| >| HTH,
| >|
| >| Bill
| >| | >| > I'm having problems getting default column values
| (which I
| >| > set by design in a table in SQL Server) correctly
| >| > updating a DataSet after a new row is entered into
| the
| >| > DataSet(except the column in question) and the
| >| > DataAdapter.Update called.
| >| >
| >| > When I set up my DataTable in the DataSet(with a
| >| > DataAdapter.FillSchema), shouldn't a column's
| >| > DefaultValue be set to the default value specified
| in the
| >| > SQL table?
| >| >
| >| > Michael
| >| >
| >| >
| >|
| >|
| >|
| >
| >.
| >
|
 
Back
Top