how to use default value in sqlCommand

  • Thread starter Thread starter tonyqus
  • Start date Start date
T

tonyqus

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
 
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.
__________________________________
 
Back
Top