Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data type confusion

Status
Not open for further replies.

123ASP

MIS
Nov 2, 2002
239
US
hi
I am new to asp.net. I appreciate your assistance in clarifying the following:
Which Data type I should use
1. Ado type vs .net type vs sqlDbType vs sqlType

I did the following in visual studio
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlDbType
Imports System.Data.SqlTypes
1. Dim x As Data.SqlDbType
2. Dim y As Data.SqlTypes.SqlDateTime

#1. stopped and did not show me intellisence of different datatype,
#2. it shows me all different type of datatype
I read somewhere that I have to use SqlDbType in a command parameter. Is it a must and if so, how can I get datetime datatime in the following parameter sample
myCmd.Parameters.Add(New SqlParameter("@mydate",SqlDbType.NChar,10))

as you see, I have not used datetime datatype, because I could not find its type, instead I used Nchar and it worked,but the problem is when I do not insert a value it automatically put 1900/1/1 by default.

any idea thanks
Al
 
OleDb vs. Sql:

Use Sql family if you're talking to MSDE or SQL Server. Use OleDb family when talking to other databases. Use the Odbc family when talking to databases that don't have an OleDB driver.

The type in the Parameter constructor should match the datatype of your column in the database. If you're storing a date in your database, create the table with a date or datetime column type. Then use a Date or DateTime SqlDbType value. And lastly, pass in something that ADO can recognize as a date.

If you're starting with a date stored in a string (BTW, storing dates in strings is a bad idea), use the Convert.ToDateTime() method to convert it to a DateTime object. Otherwise, use a variable of type DateTime in your code, and you'll have no problems.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top