hello guys am a beginner to vb.net am trying to make an application for my videos
i have a problem to insert birthdate of the actor to the sql server database
the birthdate field in sql server is set to date not datetime
let's say birthdate = 02-13-1980
when i click the save button am getting the error
incorrect syntax near '02-13-1980'
this is my class code
ImportsSystem.Data.Sql
ImportsSystem.Data.SqlClient
PublicClass SQL_Control
PublicSQLConAsNewSqlConnectionWith{.ConnectionString="Server=TRUCK-PC\TRUCK;Database=Videos;User=sa;Pwd=123456;"}
PublicSQLCmdAsSqlCommand
Public SQLDA AsSqlDataAdapter
PublicSQLDatasetAsDataSet
PublicFunctionHasConnection()AsBoolean
Try
SQLCon.Open()
SQLCon.Close()
ReturnTrue
Catch ex AsException
MsgBox(ex.Message)
ReturnFalse
EndTry
EndFunction
PublicSubRunQuery(QueryAsString)
Try
SQLCon.Open()
SQLCmd=NewSqlCommand(Query,SQLCon)
SQLDA =NewSqlDataAdapter(SQLCmd)
SQLDataset=NewDataSet
SQLDA.Fill(SQLDataset)
SQLCon.Close()
Catch ex AsException
MsgBox(ex.Message)
IfSQLCon.State=ConnectionState.OpenThen
SQLCon.Close()
EndIf
EndTry
EndSub
PublicSubAddNewActor(S_ActorName AsString, S_ActorNationality AsString, S_ActorBirthDate AsDate)
Try
Dim strInsert AsString="INSERT INTO Videos (Actor_Name,Actor_Nationality,Actor_Birth_Date) "& _
"VALUES ("& _
"'"& S_ActorName &"',"& _
"'"& S_ActorNationality &"',"& _
"'"& S_ActorBirthDate &"'"
MsgBox(strInsert)
SQLCon.Open()
SQLCmd=NewSqlCommand(strInsert,SQLCon)
SQLCmd.ExecuteNonQuery()
SQLCon.Close()
Catch ex AsException
MsgBox(ex.Message)
EndTry
EndSub
EndClass
this is my form code
ImportsSystem.Data.SqlClient
PublicClass F2_Actors
Dim SQL AsNew SQL_Control
PrivateSubButton1_Click(sender AsObject, e AsEventArgs)HandlesButton1.Click
SQL.RunQuery("SELECT * FROM tbl_actors WHERE tbl_actors.Actor_Name = '"&ActorName.Text&"' ")
If SQL.SQLDataset.Tables(0).Rows.Count>0Then
MsgBox("Actor already exist",MsgBoxStyle.Critical,"Videos Database - Adding New Actor")
Else
AddActor()
EndIf
EndSub
PublicSubAddActor()
SQL.AddNewActor(ActorName.Text,ActorNationality.Text,ActorBirthDate.Text)
EndSub
EndClass
and thanks for your help
i have a problem to insert birthdate of the actor to the sql server database
the birthdate field in sql server is set to date not datetime
let's say birthdate = 02-13-1980
when i click the save button am getting the error
incorrect syntax near '02-13-1980'
this is my class code
ImportsSystem.Data.Sql
ImportsSystem.Data.SqlClient
PublicClass SQL_Control
PublicSQLConAsNewSqlConnectionWith{.ConnectionString="Server=TRUCK-PC\TRUCK;Database=Videos;User=sa;Pwd=123456;"}
PublicSQLCmdAsSqlCommand
Public SQLDA AsSqlDataAdapter
PublicSQLDatasetAsDataSet
PublicFunctionHasConnection()AsBoolean
Try
SQLCon.Open()
SQLCon.Close()
ReturnTrue
Catch ex AsException
MsgBox(ex.Message)
ReturnFalse
EndTry
EndFunction
PublicSubRunQuery(QueryAsString)
Try
SQLCon.Open()
SQLCmd=NewSqlCommand(Query,SQLCon)
SQLDA =NewSqlDataAdapter(SQLCmd)
SQLDataset=NewDataSet
SQLDA.Fill(SQLDataset)
SQLCon.Close()
Catch ex AsException
MsgBox(ex.Message)
IfSQLCon.State=ConnectionState.OpenThen
SQLCon.Close()
EndIf
EndTry
EndSub
PublicSubAddNewActor(S_ActorName AsString, S_ActorNationality AsString, S_ActorBirthDate AsDate)
Try
Dim strInsert AsString="INSERT INTO Videos (Actor_Name,Actor_Nationality,Actor_Birth_Date) "& _
"VALUES ("& _
"'"& S_ActorName &"',"& _
"'"& S_ActorNationality &"',"& _
"'"& S_ActorBirthDate &"'"
MsgBox(strInsert)
SQLCon.Open()
SQLCmd=NewSqlCommand(strInsert,SQLCon)
SQLCmd.ExecuteNonQuery()
SQLCon.Close()
Catch ex AsException
MsgBox(ex.Message)
EndTry
EndSub
EndClass
this is my form code
ImportsSystem.Data.SqlClient
PublicClass F2_Actors
Dim SQL AsNew SQL_Control
PrivateSubButton1_Click(sender AsObject, e AsEventArgs)HandlesButton1.Click
SQL.RunQuery("SELECT * FROM tbl_actors WHERE tbl_actors.Actor_Name = '"&ActorName.Text&"' ")
If SQL.SQLDataset.Tables(0).Rows.Count>0Then
MsgBox("Actor already exist",MsgBoxStyle.Critical,"Videos Database - Adding New Actor")
Else
AddActor()
EndIf
EndSub
PublicSubAddActor()
SQL.AddNewActor(ActorName.Text,ActorNationality.Text,ActorBirthDate.Text)
EndSub
EndClass
and thanks for your help
Attachments
Last edited: