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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateTime Conversion question

Status
Not open for further replies.

misman2973

Technical User
Jul 1, 2003
5
US
Hello everyone,
I get the following error when submitting my form:
"Failed to convert parameter value from a String to a DateTime."

Do I need to use "parse" or "format" before I send my value off to the DB. Whensubmittimg all others the insert sp works fine, just bombs on datetime conversion.
Any suggestions would be greatly appreciated.
Thanks,
C

code for insert:

cmdCommand.Parameters.Add("@Ident", SqlDbType.VarChar, 100).Value = txtdocident.Text
cmdCommand.Parameters.Add("@Vol", SqlDbType.VarChar, 50).Value = txtvolnumber.Text
cmdCommand.Parameters.Add("@Type", SqlDbType.VarChar, 255).Value = cmbType.SelectedValue
cmdCommand.Parameters.Add("@Title", SqlDbType.VarChar, 2000).Value = txtardoctitle.Value
cmdCommand.Parameters.Add("@Keyw", SqlDbType.VarChar, 2000).Value = txtarkeyword.Value
cmdCommand.Parameters.Add("@Summ", SqlDbType.VarChar, 2000).Value = txtarsummary.Value
cmdCommand.Parameters.Add("@Related", SqlDbType.VarChar, 2000).Value = txtarreldoc.Value
cmdCommand.Parameters.Add("@Datereq", SqlDbType.DateTime).Value = txtdateappr.Text
cmdCommand.Parameters.Add("@Assby", SqlDbType.VarChar, 50).Value = txtassby.Text
cmdCommand.Parameters.Add("@Dateappr", SqlDbType.VarChar, 50).Value = txtdateappr.Text
cmdCommand.Parameters.Add("@Recby", SqlDbType.VarChar, 50).Value = cmbRecBy.SelectedValue
cmdCommand.Parameters.Add("@Location", SqlDbType.VarChar, 50).Value = cmbloc.SelectedValue
cmdCommand.Parameters.Add("@Resp", SqlDbType.VarChar, 255).Value = txtresponsible.Text
cmdCommand.Parameters.Add("@Author", SqlDbType.VarChar, 50).Value = txtauthor.Text
cmdCommand.Parameters.Add("@Ref", SqlDbType.VarChar, 2000).Value = txtarref.Value
cmdCommand.Parameters.Add("@Dept", SqlDbType.VarChar, 20).Value = cmbDept.SelectedValue
cmdCommand.Parameters.Add("@Hardcpy", SqlDbType.VarChar, 255).Value = txthardcopy.Text
cmdCommand.Parameters.AddWithValue("@bAuto", "1")
cmdCommand.ExecuteNonQuery()


Insert sp:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[qparmInsertInfo]
(
@Ident varchar(100),
@Vol varchar(50),
@Type varchar(50),
@Title varchar(255),
@Keyw varchar(255),
@Summ varchar(255),
@Related varchar(255),
@Datereq datetime,
@Assby varchar(50),
@Dateappr varchar(50),
@Recby varchar(50),
@Location varchar(25),
@Resp varchar(50),
@Author varchar(50),
@Ref varchar(255),
@Dept varchar(20),
@Hardcpy varchar(50),
@bAuto bit = 1
)
as
if exists
-- You cannot register usernames already registered on the database twice.

(
select docident from tblDocument where docident = @Ident
)
return 1
else
insert tblDocument(docident,
docvol,
doctype,
doctitle,
dockeyword,
docsumm,
docrel,
docdatereq,
docassby,
docdateappr,
docrecby,
docloc,
docresp,
docauthor,
docref,
docdept,
dochardcopy,
bAuto)
values(@Ident,
@Vol,
@Type,
@Title,
@Keyw,
@Summ,
@Related,
@Datereq,
@Assby,
@Dateappr,
@Recby,
@Location,
@Resp,
@Author,
@Ref,
@Dept,
@Hardcpy,
@bAuto)
 
Well it would seem the value for the @Datereq parameter is not in a correct datetime format. You are gettting a date from a textbox which could cause problems. Make sure you are entering a valid date.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top