Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SYNTAX ERROR CONVERTING DATETIME

Author  Topic 

alperozgur
Starting Member

16 Posts

Posted - 2004-08-18 : 05:15:34
When i try to insert data to sql server by visualbasic .net 2003 by using a store procedure i got the error "syntax error converting datetime from character string."
here is the details :

STORE PROCEDURE
CREATE PROCEDURE bpg_mi_yeni_teminat_mektubu

@SMCode varchar(50),
@CustCode varchar(50),
@Lehdar varchar (500),
@BTMNo varchar (500),
@dtpBTMTar varchar(50),
@dtpBTMVadeTar varchar(50),

@banka int,
@sube int,
@BTMTutar float,
@PB smallint,
@AlinmaNeden smallint,
@BTMDurum varchar(10),
@BTMDurumTar varchar(50),
@SNO varchar(100)

AS

INSERT INTO BPG_TEMINAT_MEKTUPLARI (SM, BAYI, LEHDAR,BTM_NO, BTM_TARIH, BTM_VADESI, BANKA, SUBE, BTM_TUTAR,PARA_BIRIMI,
ALINMA_NEDENI, BTM_DURUMU, TARIH,SNO)VALUES(@SMCode,@CustCode,@Lehdar,@BTMNo,@dtpBTMTar,@dtpBTMVadeTar,@banka,@sube,
@BTMTutar,@PB,@AlinmaNeden,@BTMDurum,@BTMDurumTar,@SNO)
GO


IN CODE

Friend WithEvents dtpBTMTar As System.Windows.Forms.DateTimePicker
Friend WithEvents dtpBTMVadeTar As System.Windows.Forms.DateTimePicker
Friend WithEvents dtpBTMDurumTar As System.Windows.Forms.DateTimePicker
Dim Btmvadetar As String
Dim durum, durumtar As String

szsql = " EXEC bpg_mi_yeni_teminat_mektubu " & _
"'" & txtSMCode.Text & "'" & _
"," & "'" & txtCustCode.Text & "'" & _
"," & "'" & txtLehdar.Text & "'" & _
"," & "'" & txtBTMNo.Text & "'" & _
"," & "'" & dtpBTMTar.Text & "'" & _
"," & "" & Btmvadetar & "" & _

"," & "" & Szdegbanka & "" & _
"," & "" & Szdegsube & "" & _
"," & "'" & Asil & "'" & _
"," & "" & cmbPB.SelectedIndex & "" & _
"," & "" & cmbAlinmaNeden.SelectedIndex & "" & _
"," & "" & durum & "" & _
"," & "" & durumtar & "" & _
"," & "'" & txtSNo.Text & "'"

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-18 : 05:29:11
the only thing i can think of is that your dtpBTMTar.Text is empty (= "").
this would be much easier for you if you used SqlDataAdapter and SQLCommand. there you just add the parameters and that's it.

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

alperozgur
Starting Member

16 Posts

Posted - 2004-08-18 : 06:01:27
no it's not empty... i get the szsql by msgbox and everything is ok.
Go to Top of Page

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2004-08-18 : 08:58:05
Looks like your dates are in dd/mm/yyyy format. What date format do you usually use in your part of the world (guessing its Turkey)? You need to format the strings that hold your dates, to send the date in either mm/dd/yyyy which is supported by SQL Server. It's even better if you use the internationally recognized format yyyymmdd. The best suggestion, though, is as spirit1 suggested - use a SQLCommand and paramters to call the stored proc, you don't have to worry about any formatting then.

OS
Go to Top of Page
   

- Advertisement -