In Sql Server, I can use syntax to insert a record with default value:
insert table1(a,b,c)values('A','B',default)

But in .Net, if I want to use default value in Adapter.InsertCommand,for
example,

SqlAdapObj.InsertCommand.Parameters.Add(New
SqlClient.SqlParameter("@testField"))
SqlAdapObj.InsertCommand.Parameters("@testField").Value=default

There is no "default" in C# language, so it says error occurred,what const
variable should I use to do so

Re: how to use default value in sqlCommand by William

William
Mon Jul 26 15:27:33 CDT 2004

ADO.NET does not know how to handle DEFAULT syntax on its own, but you can
handle this issue by creating a custom SqlCommand that uses the DEFAULT
keyword to load the default value defined for a column. In this case you
would not define the third column (as you have done)--so you only need the
first two parameters defined.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"tonyqus" <tonyqus@163.com> wrote in message
news:eFqQFutcEHA.1000@TK2MSFTNGP12.phx.gbl...
> In Sql Server, I can use syntax to insert a record with default value:
> insert table1(a,b,c)values('A','B',default)
>
> But in .Net, if I want to use default value in Adapter.InsertCommand,for
> example,
>
> SqlAdapObj.InsertCommand.Parameters.Add(New
> SqlClient.SqlParameter("@testField"))
> SqlAdapObj.InsertCommand.Parameters("@testField").Value=default
>
> There is no "default" in C# language, so it says error occurred,what const
> variable should I use to do so
>
>



Re: how to use default value in sqlCommand by Tony

Tony
Mon Jul 26 02:03:52 CDT 2004

The default will be applied if you don't provide a value of the column.

Tony

"tonyqus" <tonyqus@163.com> wrote in message
news:eFqQFutcEHA.1000@TK2MSFTNGP12.phx.gbl...
> In Sql Server, I can use syntax to insert a record with default value:
> insert table1(a,b,c)values('A','B',default)
>
> But in .Net, if I want to use default value in Adapter.InsertCommand,for
> example,
>
> SqlAdapObj.InsertCommand.Parameters.Add(New
> SqlClient.SqlParameter("@testField"))
> SqlAdapObj.InsertCommand.Parameters("@testField").Value=default
>
> There is no "default" in C# language, so it says error occurred,what const
> variable should I use to do so
>
>