473,725 Members | 2,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding record to sql db

hello all...

im trying to add a record to an sql db on ms sql server 2000, using vb.net.

seems to be working.. except for one thing, one of the columns in the
database is a bit datatype, and though i get no syntax errors when
compiling, i get an error indicated that the data would be truncated. the
field is login_status.

ive tried in quotes and not, giving it an integer variable with the number 1
in it, true/false statements.. ive tried a bunch of stuff... has me real
stumped..

have any ideas?

thanks
here is the error it spits out.

<b>* error while uploading original data</b>.<br />String or binary data
would be truncated.The statement has been terminated..Net SqlClient Data
Provider


--------------------------------------------------------------------------
here is the code:
--------------------------------------------------------------------------
Imports System.Data

Imports System.Data.Sql Client

Public Class WebForm1

Inherits System.Web.UI.P age




Public Sub Register_User(B yVal sender As Object, ByVal E As EventArgs)

Dim dbConnStr As String = "user id=**(blanked for
security)***;pa ssword=**(blank ed for
security)**;dat abase=BCdb;serv er=localhost"

Dim dbConn As New System.Data.Sql Client.SqlConne ction(dbConnStr )



Try

Dim cmd As New SqlCommand("add CustomerSQL", dbConn)

cmd.CommandType = CommandType.Sto redProcedure

cmd.Parameters. Add(New SqlParameter("@ username", SqlDbType.Char, 19))

cmd.Parameters. Add(New SqlParameter("@ fullname", SqlDbType.VarCh ar, 27))

cmd.Parameters. Add(New SqlParameter("@ password", SqlDbType.Char, 7))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nbr ", SqlDbType.Char, 18))

cmd.Parameters. Add(New SqlParameter("@ credit_card_exp iry_date",
SqlDbType.DateT ime))

cmd.Parameters. Add(New SqlParameter("@ mailing_address ", SqlDbType.VarCh ar,
100))

cmd.Parameters. Add(New SqlParameter("@ phone_nbr", SqlDbType.Char, 14))

cmd.Parameters. Add(New SqlParameter("@ email_address", SqlDbType.Char, 50))

cmd.Parameters. Add(New SqlParameter("@ login_status", SqlDbType.Bit))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nam e", SqlDbType.Char,
27))

cmd.Parameters. Item("@username ").Value = RegUsrnameTXT.T ext

cmd.Parameters. Item("@fullname ").Value = RegFullnameTXT. Text

cmd.Parameters. Item("@password ").Value = RegPasswordTXT. Text

cmd.Parameters. Item("@credit_c ard_nbr").Value = RegCreditcardnu mberTXT.Text

cmd.Parameters. Item("@credit_c ard_expiry_date ").Value =
RegCreditcardex piryTXT.Text

cmd.Parameters. Item("@mailing_ address").Value = RegAddressTXT.T ext

cmd.Parameters. Item("@email_ad dress").Value = RegEmailTXT.Tex t

cmd.Parameters. Item("@phone_nb r").Value = RegPhoneTXT.Tex t

cmd.Parameters. Item("@login_st atus").Value = 1

cmd.Parameters. Item("@credit_c ard_name").Valu e = RegCreditcardna meTXT.Text

'opent the connection to the database

dbConn.Open()

'execute sql statement

cmd.ExecuteNonQ uery()

dbConn.Close()

Catch objError As Exception

dberror.Text = "<b>* error while uploading original data</b>.<br />" &
objError.Messag e & objError.Source

Exit Sub

Finally

If dbConn.State = ConnectionState .Open Then

dbConn.Close()

End If

End Try

End Sub

End Class

----------------------------------------------------------------------------
---

Nov 20 '05 #1
20 2137
did you try to just use the integer 1 or 0 with no quotes?
"Bryan" <ca**********@r ogers.com> wrote in message
news:5y******** ************@ne ws04.bloor.is.n et.cable.rogers .com...
hello all...

im trying to add a record to an sql db on ms sql server 2000, using vb.net.
seems to be working.. except for one thing, one of the columns in the
database is a bit datatype, and though i get no syntax errors when
compiling, i get an error indicated that the data would be truncated. the
field is login_status.

ive tried in quotes and not, giving it an integer variable with the number 1 in it, true/false statements.. ive tried a bunch of stuff... has me real
stumped..

have any ideas?

thanks
here is the error it spits out.

<b>* error while uploading original data</b>.<br />String or binary data
would be truncated.The statement has been terminated..Net SqlClient Data
Provider


--------------------------------------------------------------------------
here is the code:
--------------------------------------------------------------------------
Imports System.Data

Imports System.Data.Sql Client

Public Class WebForm1

Inherits System.Web.UI.P age




Public Sub Register_User(B yVal sender As Object, ByVal E As EventArgs)

Dim dbConnStr As String = "user id=**(blanked for
security)***;pa ssword=**(blank ed for
security)**;dat abase=BCdb;serv er=localhost"

Dim dbConn As New System.Data.Sql Client.SqlConne ction(dbConnStr )



Try

Dim cmd As New SqlCommand("add CustomerSQL", dbConn)

cmd.CommandType = CommandType.Sto redProcedure

cmd.Parameters. Add(New SqlParameter("@ username", SqlDbType.Char, 19))

cmd.Parameters. Add(New SqlParameter("@ fullname", SqlDbType.VarCh ar, 27))

cmd.Parameters. Add(New SqlParameter("@ password", SqlDbType.Char, 7))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nbr ", SqlDbType.Char, 18))
cmd.Parameters. Add(New SqlParameter("@ credit_card_exp iry_date",
SqlDbType.DateT ime))

cmd.Parameters. Add(New SqlParameter("@ mailing_address ", SqlDbType.VarCh ar,
100))

cmd.Parameters. Add(New SqlParameter("@ phone_nbr", SqlDbType.Char, 14))

cmd.Parameters. Add(New SqlParameter("@ email_address", SqlDbType.Char, 50))

cmd.Parameters. Add(New SqlParameter("@ login_status", SqlDbType.Bit))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nam e", SqlDbType.Char,
27))

cmd.Parameters. Item("@username ").Value = RegUsrnameTXT.T ext

cmd.Parameters. Item("@fullname ").Value = RegFullnameTXT. Text

cmd.Parameters. Item("@password ").Value = RegPasswordTXT. Text

cmd.Parameters. Item("@credit_c ard_nbr").Value = RegCreditcardnu mberTXT.Text
cmd.Parameters. Item("@credit_c ard_expiry_date ").Value =
RegCreditcardex piryTXT.Text

cmd.Parameters. Item("@mailing_ address").Value = RegAddressTXT.T ext

cmd.Parameters. Item("@email_ad dress").Value = RegEmailTXT.Tex t

cmd.Parameters. Item("@phone_nb r").Value = RegPhoneTXT.Tex t

cmd.Parameters. Item("@login_st atus").Value = 1

cmd.Parameters. Item("@credit_c ard_name").Valu e = RegCreditcardna meTXT.Text

'opent the connection to the database

dbConn.Open()

'execute sql statement

cmd.ExecuteNonQ uery()

dbConn.Close()

Catch objError As Exception

dberror.Text = "<b>* error while uploading original data</b>.<br />" &
objError.Messag e & objError.Source

Exit Sub

Finally

If dbConn.State = ConnectionState .Open Then

dbConn.Close()

End If

End Try

End Sub

End Class

-------------------------------------------------------------------------- -- ---

Nov 20 '05 #2
did you try to just use the integer 1 or 0 with no quotes?
"Bryan" <ca**********@r ogers.com> wrote in message
news:5y******** ************@ne ws04.bloor.is.n et.cable.rogers .com...
hello all...

im trying to add a record to an sql db on ms sql server 2000, using vb.net.
seems to be working.. except for one thing, one of the columns in the
database is a bit datatype, and though i get no syntax errors when
compiling, i get an error indicated that the data would be truncated. the
field is login_status.

ive tried in quotes and not, giving it an integer variable with the number 1 in it, true/false statements.. ive tried a bunch of stuff... has me real
stumped..

have any ideas?

thanks
here is the error it spits out.

<b>* error while uploading original data</b>.<br />String or binary data
would be truncated.The statement has been terminated..Net SqlClient Data
Provider


--------------------------------------------------------------------------
here is the code:
--------------------------------------------------------------------------
Imports System.Data

Imports System.Data.Sql Client

Public Class WebForm1

Inherits System.Web.UI.P age




Public Sub Register_User(B yVal sender As Object, ByVal E As EventArgs)

Dim dbConnStr As String = "user id=**(blanked for
security)***;pa ssword=**(blank ed for
security)**;dat abase=BCdb;serv er=localhost"

Dim dbConn As New System.Data.Sql Client.SqlConne ction(dbConnStr )



Try

Dim cmd As New SqlCommand("add CustomerSQL", dbConn)

cmd.CommandType = CommandType.Sto redProcedure

cmd.Parameters. Add(New SqlParameter("@ username", SqlDbType.Char, 19))

cmd.Parameters. Add(New SqlParameter("@ fullname", SqlDbType.VarCh ar, 27))

cmd.Parameters. Add(New SqlParameter("@ password", SqlDbType.Char, 7))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nbr ", SqlDbType.Char, 18))
cmd.Parameters. Add(New SqlParameter("@ credit_card_exp iry_date",
SqlDbType.DateT ime))

cmd.Parameters. Add(New SqlParameter("@ mailing_address ", SqlDbType.VarCh ar,
100))

cmd.Parameters. Add(New SqlParameter("@ phone_nbr", SqlDbType.Char, 14))

cmd.Parameters. Add(New SqlParameter("@ email_address", SqlDbType.Char, 50))

cmd.Parameters. Add(New SqlParameter("@ login_status", SqlDbType.Bit))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nam e", SqlDbType.Char,
27))

cmd.Parameters. Item("@username ").Value = RegUsrnameTXT.T ext

cmd.Parameters. Item("@fullname ").Value = RegFullnameTXT. Text

cmd.Parameters. Item("@password ").Value = RegPasswordTXT. Text

cmd.Parameters. Item("@credit_c ard_nbr").Value = RegCreditcardnu mberTXT.Text
cmd.Parameters. Item("@credit_c ard_expiry_date ").Value =
RegCreditcardex piryTXT.Text

cmd.Parameters. Item("@mailing_ address").Value = RegAddressTXT.T ext

cmd.Parameters. Item("@email_ad dress").Value = RegEmailTXT.Tex t

cmd.Parameters. Item("@phone_nb r").Value = RegPhoneTXT.Tex t

cmd.Parameters. Item("@login_st atus").Value = 1

cmd.Parameters. Item("@credit_c ard_name").Valu e = RegCreditcardna meTXT.Text

'opent the connection to the database

dbConn.Open()

'execute sql statement

cmd.ExecuteNonQ uery()

dbConn.Close()

Catch objError As Exception

dberror.Text = "<b>* error while uploading original data</b>.<br />" &
objError.Messag e & objError.Source

Exit Sub

Finally

If dbConn.State = ConnectionState .Open Then

dbConn.Close()

End If

End Try

End Sub

End Class

-------------------------------------------------------------------------- -- ---

Nov 20 '05 #3
Bryan:

What is the datatype of the field in SqlServer? Bit or Binary? The Param
type is specified as Bit but by the Exception message, I'm wondering if it's
not Binary in the DB. If so, I believe changing the db type in the client
code to SqlDbType.Binar y or changing the data type server side to Bit may do
it for you.

HTH,

Bill
"Bryan" <ca**********@r ogers.com> wrote in message
news:5y******** ************@ne ws04.bloor.is.n et.cable.rogers .com...
hello all...

im trying to add a record to an sql db on ms sql server 2000, using vb.net.
seems to be working.. except for one thing, one of the columns in the
database is a bit datatype, and though i get no syntax errors when
compiling, i get an error indicated that the data would be truncated. the
field is login_status.

ive tried in quotes and not, giving it an integer variable with the number 1 in it, true/false statements.. ive tried a bunch of stuff... has me real
stumped..

have any ideas?

thanks
here is the error it spits out.

<b>* error while uploading original data</b>.<br />String or binary data
would be truncated.The statement has been terminated..Net SqlClient Data
Provider


--------------------------------------------------------------------------
here is the code:
--------------------------------------------------------------------------
Imports System.Data

Imports System.Data.Sql Client

Public Class WebForm1

Inherits System.Web.UI.P age




Public Sub Register_User(B yVal sender As Object, ByVal E As EventArgs)

Dim dbConnStr As String = "user id=**(blanked for
security)***;pa ssword=**(blank ed for
security)**;dat abase=BCdb;serv er=localhost"

Dim dbConn As New System.Data.Sql Client.SqlConne ction(dbConnStr )



Try

Dim cmd As New SqlCommand("add CustomerSQL", dbConn)

cmd.CommandType = CommandType.Sto redProcedure

cmd.Parameters. Add(New SqlParameter("@ username", SqlDbType.Char, 19))

cmd.Parameters. Add(New SqlParameter("@ fullname", SqlDbType.VarCh ar, 27))

cmd.Parameters. Add(New SqlParameter("@ password", SqlDbType.Char, 7))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nbr ", SqlDbType.Char, 18))
cmd.Parameters. Add(New SqlParameter("@ credit_card_exp iry_date",
SqlDbType.DateT ime))

cmd.Parameters. Add(New SqlParameter("@ mailing_address ", SqlDbType.VarCh ar,
100))

cmd.Parameters. Add(New SqlParameter("@ phone_nbr", SqlDbType.Char, 14))

cmd.Parameters. Add(New SqlParameter("@ email_address", SqlDbType.Char, 50))

cmd.Parameters. Add(New SqlParameter("@ login_status", SqlDbType.Bit))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nam e", SqlDbType.Char,
27))

cmd.Parameters. Item("@username ").Value = RegUsrnameTXT.T ext

cmd.Parameters. Item("@fullname ").Value = RegFullnameTXT. Text

cmd.Parameters. Item("@password ").Value = RegPasswordTXT. Text

cmd.Parameters. Item("@credit_c ard_nbr").Value = RegCreditcardnu mberTXT.Text
cmd.Parameters. Item("@credit_c ard_expiry_date ").Value =
RegCreditcardex piryTXT.Text

cmd.Parameters. Item("@mailing_ address").Value = RegAddressTXT.T ext

cmd.Parameters. Item("@email_ad dress").Value = RegEmailTXT.Tex t

cmd.Parameters. Item("@phone_nb r").Value = RegPhoneTXT.Tex t

cmd.Parameters. Item("@login_st atus").Value = 1

cmd.Parameters. Item("@credit_c ard_name").Valu e = RegCreditcardna meTXT.Text

'opent the connection to the database

dbConn.Open()

'execute sql statement

cmd.ExecuteNonQ uery()

dbConn.Close()

Catch objError As Exception

dberror.Text = "<b>* error while uploading original data</b>.<br />" &
objError.Messag e & objError.Source

Exit Sub

Finally

If dbConn.State = ConnectionState .Open Then

dbConn.Close()

End If

End Try

End Sub

End Class

-------------------------------------------------------------------------- -- ---

Nov 20 '05 #4
Bryan:

What is the datatype of the field in SqlServer? Bit or Binary? The Param
type is specified as Bit but by the Exception message, I'm wondering if it's
not Binary in the DB. If so, I believe changing the db type in the client
code to SqlDbType.Binar y or changing the data type server side to Bit may do
it for you.

HTH,

Bill
"Bryan" <ca**********@r ogers.com> wrote in message
news:5y******** ************@ne ws04.bloor.is.n et.cable.rogers .com...
hello all...

im trying to add a record to an sql db on ms sql server 2000, using vb.net.
seems to be working.. except for one thing, one of the columns in the
database is a bit datatype, and though i get no syntax errors when
compiling, i get an error indicated that the data would be truncated. the
field is login_status.

ive tried in quotes and not, giving it an integer variable with the number 1 in it, true/false statements.. ive tried a bunch of stuff... has me real
stumped..

have any ideas?

thanks
here is the error it spits out.

<b>* error while uploading original data</b>.<br />String or binary data
would be truncated.The statement has been terminated..Net SqlClient Data
Provider


--------------------------------------------------------------------------
here is the code:
--------------------------------------------------------------------------
Imports System.Data

Imports System.Data.Sql Client

Public Class WebForm1

Inherits System.Web.UI.P age




Public Sub Register_User(B yVal sender As Object, ByVal E As EventArgs)

Dim dbConnStr As String = "user id=**(blanked for
security)***;pa ssword=**(blank ed for
security)**;dat abase=BCdb;serv er=localhost"

Dim dbConn As New System.Data.Sql Client.SqlConne ction(dbConnStr )



Try

Dim cmd As New SqlCommand("add CustomerSQL", dbConn)

cmd.CommandType = CommandType.Sto redProcedure

cmd.Parameters. Add(New SqlParameter("@ username", SqlDbType.Char, 19))

cmd.Parameters. Add(New SqlParameter("@ fullname", SqlDbType.VarCh ar, 27))

cmd.Parameters. Add(New SqlParameter("@ password", SqlDbType.Char, 7))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nbr ", SqlDbType.Char, 18))
cmd.Parameters. Add(New SqlParameter("@ credit_card_exp iry_date",
SqlDbType.DateT ime))

cmd.Parameters. Add(New SqlParameter("@ mailing_address ", SqlDbType.VarCh ar,
100))

cmd.Parameters. Add(New SqlParameter("@ phone_nbr", SqlDbType.Char, 14))

cmd.Parameters. Add(New SqlParameter("@ email_address", SqlDbType.Char, 50))

cmd.Parameters. Add(New SqlParameter("@ login_status", SqlDbType.Bit))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nam e", SqlDbType.Char,
27))

cmd.Parameters. Item("@username ").Value = RegUsrnameTXT.T ext

cmd.Parameters. Item("@fullname ").Value = RegFullnameTXT. Text

cmd.Parameters. Item("@password ").Value = RegPasswordTXT. Text

cmd.Parameters. Item("@credit_c ard_nbr").Value = RegCreditcardnu mberTXT.Text
cmd.Parameters. Item("@credit_c ard_expiry_date ").Value =
RegCreditcardex piryTXT.Text

cmd.Parameters. Item("@mailing_ address").Value = RegAddressTXT.T ext

cmd.Parameters. Item("@email_ad dress").Value = RegEmailTXT.Tex t

cmd.Parameters. Item("@phone_nb r").Value = RegPhoneTXT.Tex t

cmd.Parameters. Item("@login_st atus").Value = 1

cmd.Parameters. Item("@credit_c ard_name").Valu e = RegCreditcardna meTXT.Text

'opent the connection to the database

dbConn.Open()

'execute sql statement

cmd.ExecuteNonQ uery()

dbConn.Close()

Catch objError As Exception

dberror.Text = "<b>* error while uploading original data</b>.<br />" &
objError.Messag e & objError.Source

Exit Sub

Finally

If dbConn.State = ConnectionState .Open Then

dbConn.Close()

End If

End Try

End Sub

End Class

-------------------------------------------------------------------------- -- ---

Nov 20 '05 #5
yes i tried with and without quotes.
i even tried creating an integer variable, assigning it the value 1 and
putting that variable in its place.. no go either.

thanks for the response,, have any other ideas?

cheers
bry

"Brian Henry" <brianiup[nospam]@adelphia.net> wrote in message
news:O9******** ******@TK2MSFTN GP09.phx.gbl...
did you try to just use the integer 1 or 0 with no quotes?
"Bryan" <ca**********@r ogers.com> wrote in message
news:5y******** ************@ne ws04.bloor.is.n et.cable.rogers .com...
hello all...

im trying to add a record to an sql db on ms sql server 2000, using vb.net.

seems to be working.. except for one thing, one of the columns in the
database is a bit datatype, and though i get no syntax errors when
compiling, i get an error indicated that the data would be truncated. the field is login_status.

ive tried in quotes and not, giving it an integer variable with the number 1
in it, true/false statements.. ive tried a bunch of stuff... has me real
stumped..

have any ideas?

thanks
here is the error it spits out.

<b>* error while uploading original data</b>.<br />String or binary data
would be truncated.The statement has been terminated..Net SqlClient Data
Provider


--------------------------------------------------------------------------
here is the code:


--------------------------------------------------------------------------
Imports System.Data

Imports System.Data.Sql Client

Public Class WebForm1

Inherits System.Web.UI.P age




Public Sub Register_User(B yVal sender As Object, ByVal E As EventArgs)

Dim dbConnStr As String = "user id=**(blanked for
security)***;pa ssword=**(blank ed for
security)**;dat abase=BCdb;serv er=localhost"

Dim dbConn As New System.Data.Sql Client.SqlConne ction(dbConnStr )



Try

Dim cmd As New SqlCommand("add CustomerSQL", dbConn)

cmd.CommandType = CommandType.Sto redProcedure

cmd.Parameters. Add(New SqlParameter("@ username", SqlDbType.Char, 19))

cmd.Parameters. Add(New SqlParameter("@ fullname", SqlDbType.VarCh ar, 27))

cmd.Parameters. Add(New SqlParameter("@ password", SqlDbType.Char, 7))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nbr ", SqlDbType.Char,

18))

cmd.Parameters. Add(New SqlParameter("@ credit_card_exp iry_date",
SqlDbType.DateT ime))

cmd.Parameters. Add(New SqlParameter("@ mailing_address ",

SqlDbType.VarCh ar, 100))

cmd.Parameters. Add(New SqlParameter("@ phone_nbr", SqlDbType.Char, 14))

cmd.Parameters. Add(New SqlParameter("@ email_address", SqlDbType.Char, 50))
cmd.Parameters. Add(New SqlParameter("@ login_status", SqlDbType.Bit))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nam e", SqlDbType.Char,
27))

cmd.Parameters. Item("@username ").Value = RegUsrnameTXT.T ext

cmd.Parameters. Item("@fullname ").Value = RegFullnameTXT. Text

cmd.Parameters. Item("@password ").Value = RegPasswordTXT. Text

cmd.Parameters. Item("@credit_c ard_nbr").Value =

RegCreditcardnu mberTXT.Text

cmd.Parameters. Item("@credit_c ard_expiry_date ").Value =
RegCreditcardex piryTXT.Text

cmd.Parameters. Item("@mailing_ address").Value = RegAddressTXT.T ext

cmd.Parameters. Item("@email_ad dress").Value = RegEmailTXT.Tex t

cmd.Parameters. Item("@phone_nb r").Value = RegPhoneTXT.Tex t

cmd.Parameters. Item("@login_st atus").Value = 1

cmd.Parameters. Item("@credit_c ard_name").Valu e = RegCreditcardna meTXT.Text
'opent the connection to the database

dbConn.Open()

'execute sql statement

cmd.ExecuteNonQ uery()

dbConn.Close()

Catch objError As Exception

dberror.Text = "<b>* error while uploading original data</b>.<br />" &
objError.Messag e & objError.Source

Exit Sub

Finally

If dbConn.State = ConnectionState .Open Then

dbConn.Close()

End If

End Try

End Sub

End Class


--------------------------------------------------------------------------
--
---


Nov 20 '05 #6
yes i tried with and without quotes.
i even tried creating an integer variable, assigning it the value 1 and
putting that variable in its place.. no go either.

thanks for the response,, have any other ideas?

cheers
bry

"Brian Henry" <brianiup[nospam]@adelphia.net> wrote in message
news:O9******** ******@TK2MSFTN GP09.phx.gbl...
did you try to just use the integer 1 or 0 with no quotes?
"Bryan" <ca**********@r ogers.com> wrote in message
news:5y******** ************@ne ws04.bloor.is.n et.cable.rogers .com...
hello all...

im trying to add a record to an sql db on ms sql server 2000, using vb.net.

seems to be working.. except for one thing, one of the columns in the
database is a bit datatype, and though i get no syntax errors when
compiling, i get an error indicated that the data would be truncated. the field is login_status.

ive tried in quotes and not, giving it an integer variable with the number 1
in it, true/false statements.. ive tried a bunch of stuff... has me real
stumped..

have any ideas?

thanks
here is the error it spits out.

<b>* error while uploading original data</b>.<br />String or binary data
would be truncated.The statement has been terminated..Net SqlClient Data
Provider


--------------------------------------------------------------------------
here is the code:


--------------------------------------------------------------------------
Imports System.Data

Imports System.Data.Sql Client

Public Class WebForm1

Inherits System.Web.UI.P age




Public Sub Register_User(B yVal sender As Object, ByVal E As EventArgs)

Dim dbConnStr As String = "user id=**(blanked for
security)***;pa ssword=**(blank ed for
security)**;dat abase=BCdb;serv er=localhost"

Dim dbConn As New System.Data.Sql Client.SqlConne ction(dbConnStr )



Try

Dim cmd As New SqlCommand("add CustomerSQL", dbConn)

cmd.CommandType = CommandType.Sto redProcedure

cmd.Parameters. Add(New SqlParameter("@ username", SqlDbType.Char, 19))

cmd.Parameters. Add(New SqlParameter("@ fullname", SqlDbType.VarCh ar, 27))

cmd.Parameters. Add(New SqlParameter("@ password", SqlDbType.Char, 7))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nbr ", SqlDbType.Char,

18))

cmd.Parameters. Add(New SqlParameter("@ credit_card_exp iry_date",
SqlDbType.DateT ime))

cmd.Parameters. Add(New SqlParameter("@ mailing_address ",

SqlDbType.VarCh ar, 100))

cmd.Parameters. Add(New SqlParameter("@ phone_nbr", SqlDbType.Char, 14))

cmd.Parameters. Add(New SqlParameter("@ email_address", SqlDbType.Char, 50))
cmd.Parameters. Add(New SqlParameter("@ login_status", SqlDbType.Bit))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nam e", SqlDbType.Char,
27))

cmd.Parameters. Item("@username ").Value = RegUsrnameTXT.T ext

cmd.Parameters. Item("@fullname ").Value = RegFullnameTXT. Text

cmd.Parameters. Item("@password ").Value = RegPasswordTXT. Text

cmd.Parameters. Item("@credit_c ard_nbr").Value =

RegCreditcardnu mberTXT.Text

cmd.Parameters. Item("@credit_c ard_expiry_date ").Value =
RegCreditcardex piryTXT.Text

cmd.Parameters. Item("@mailing_ address").Value = RegAddressTXT.T ext

cmd.Parameters. Item("@email_ad dress").Value = RegEmailTXT.Tex t

cmd.Parameters. Item("@phone_nb r").Value = RegPhoneTXT.Tex t

cmd.Parameters. Item("@login_st atus").Value = 1

cmd.Parameters. Item("@credit_c ard_name").Valu e = RegCreditcardna meTXT.Text
'opent the connection to the database

dbConn.Open()

'execute sql statement

cmd.ExecuteNonQ uery()

dbConn.Close()

Catch objError As Exception

dberror.Text = "<b>* error while uploading original data</b>.<br />" &
objError.Messag e & objError.Source

Exit Sub

Finally

If dbConn.State = ConnectionState .Open Then

dbConn.Close()

End If

End Try

End Sub

End Class


--------------------------------------------------------------------------
--
---


Nov 20 '05 #7
I noticed that also, yet the datatypes are teh same in sql and in teh vb
code. this is driving me nuts.

thanks again.
bry
"William Ryan eMVP" <bi**@NoSp4m.de vbuzz.com> wrote in message
news:eA******** ******@TK2MSFTN GP11.phx.gbl...
Bryan:

What is the datatype of the field in SqlServer? Bit or Binary? The Param
type is specified as Bit but by the Exception message, I'm wondering if it's not Binary in the DB. If so, I believe changing the db type in the client
code to SqlDbType.Binar y or changing the data type server side to Bit may do it for you.

HTH,

Bill
"Bryan" <ca**********@r ogers.com> wrote in message
news:5y******** ************@ne ws04.bloor.is.n et.cable.rogers .com...
hello all...

im trying to add a record to an sql db on ms sql server 2000, using vb.net.

seems to be working.. except for one thing, one of the columns in the
database is a bit datatype, and though i get no syntax errors when
compiling, i get an error indicated that the data would be truncated. the field is login_status.

ive tried in quotes and not, giving it an integer variable with the number 1
in it, true/false statements.. ive tried a bunch of stuff... has me real
stumped..

have any ideas?

thanks
here is the error it spits out.

<b>* error while uploading original data</b>.<br />String or binary data
would be truncated.The statement has been terminated..Net SqlClient Data
Provider


--------------------------------------------------------------------------
here is the code:


--------------------------------------------------------------------------
Imports System.Data

Imports System.Data.Sql Client

Public Class WebForm1

Inherits System.Web.UI.P age




Public Sub Register_User(B yVal sender As Object, ByVal E As EventArgs)

Dim dbConnStr As String = "user id=**(blanked for
security)***;pa ssword=**(blank ed for
security)**;dat abase=BCdb;serv er=localhost"

Dim dbConn As New System.Data.Sql Client.SqlConne ction(dbConnStr )



Try

Dim cmd As New SqlCommand("add CustomerSQL", dbConn)

cmd.CommandType = CommandType.Sto redProcedure

cmd.Parameters. Add(New SqlParameter("@ username", SqlDbType.Char, 19))

cmd.Parameters. Add(New SqlParameter("@ fullname", SqlDbType.VarCh ar, 27))

cmd.Parameters. Add(New SqlParameter("@ password", SqlDbType.Char, 7))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nbr ", SqlDbType.Char,

18))

cmd.Parameters. Add(New SqlParameter("@ credit_card_exp iry_date",
SqlDbType.DateT ime))

cmd.Parameters. Add(New SqlParameter("@ mailing_address ",

SqlDbType.VarCh ar, 100))

cmd.Parameters. Add(New SqlParameter("@ phone_nbr", SqlDbType.Char, 14))

cmd.Parameters. Add(New SqlParameter("@ email_address", SqlDbType.Char, 50))
cmd.Parameters. Add(New SqlParameter("@ login_status", SqlDbType.Bit))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nam e", SqlDbType.Char,
27))

cmd.Parameters. Item("@username ").Value = RegUsrnameTXT.T ext

cmd.Parameters. Item("@fullname ").Value = RegFullnameTXT. Text

cmd.Parameters. Item("@password ").Value = RegPasswordTXT. Text

cmd.Parameters. Item("@credit_c ard_nbr").Value =

RegCreditcardnu mberTXT.Text

cmd.Parameters. Item("@credit_c ard_expiry_date ").Value =
RegCreditcardex piryTXT.Text

cmd.Parameters. Item("@mailing_ address").Value = RegAddressTXT.T ext

cmd.Parameters. Item("@email_ad dress").Value = RegEmailTXT.Tex t

cmd.Parameters. Item("@phone_nb r").Value = RegPhoneTXT.Tex t

cmd.Parameters. Item("@login_st atus").Value = 1

cmd.Parameters. Item("@credit_c ard_name").Valu e = RegCreditcardna meTXT.Text
'opent the connection to the database

dbConn.Open()

'execute sql statement

cmd.ExecuteNonQ uery()

dbConn.Close()

Catch objError As Exception

dberror.Text = "<b>* error while uploading original data</b>.<br />" &
objError.Messag e & objError.Source

Exit Sub

Finally

If dbConn.State = ConnectionState .Open Then

dbConn.Close()

End If

End Try

End Sub

End Class


--------------------------------------------------------------------------
--
---


Nov 20 '05 #8
I noticed that also, yet the datatypes are teh same in sql and in teh vb
code. this is driving me nuts.

thanks again.
bry
"William Ryan eMVP" <bi**@NoSp4m.de vbuzz.com> wrote in message
news:eA******** ******@TK2MSFTN GP11.phx.gbl...
Bryan:

What is the datatype of the field in SqlServer? Bit or Binary? The Param
type is specified as Bit but by the Exception message, I'm wondering if it's not Binary in the DB. If so, I believe changing the db type in the client
code to SqlDbType.Binar y or changing the data type server side to Bit may do it for you.

HTH,

Bill
"Bryan" <ca**********@r ogers.com> wrote in message
news:5y******** ************@ne ws04.bloor.is.n et.cable.rogers .com...
hello all...

im trying to add a record to an sql db on ms sql server 2000, using vb.net.

seems to be working.. except for one thing, one of the columns in the
database is a bit datatype, and though i get no syntax errors when
compiling, i get an error indicated that the data would be truncated. the field is login_status.

ive tried in quotes and not, giving it an integer variable with the number 1
in it, true/false statements.. ive tried a bunch of stuff... has me real
stumped..

have any ideas?

thanks
here is the error it spits out.

<b>* error while uploading original data</b>.<br />String or binary data
would be truncated.The statement has been terminated..Net SqlClient Data
Provider


--------------------------------------------------------------------------
here is the code:


--------------------------------------------------------------------------
Imports System.Data

Imports System.Data.Sql Client

Public Class WebForm1

Inherits System.Web.UI.P age




Public Sub Register_User(B yVal sender As Object, ByVal E As EventArgs)

Dim dbConnStr As String = "user id=**(blanked for
security)***;pa ssword=**(blank ed for
security)**;dat abase=BCdb;serv er=localhost"

Dim dbConn As New System.Data.Sql Client.SqlConne ction(dbConnStr )



Try

Dim cmd As New SqlCommand("add CustomerSQL", dbConn)

cmd.CommandType = CommandType.Sto redProcedure

cmd.Parameters. Add(New SqlParameter("@ username", SqlDbType.Char, 19))

cmd.Parameters. Add(New SqlParameter("@ fullname", SqlDbType.VarCh ar, 27))

cmd.Parameters. Add(New SqlParameter("@ password", SqlDbType.Char, 7))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nbr ", SqlDbType.Char,

18))

cmd.Parameters. Add(New SqlParameter("@ credit_card_exp iry_date",
SqlDbType.DateT ime))

cmd.Parameters. Add(New SqlParameter("@ mailing_address ",

SqlDbType.VarCh ar, 100))

cmd.Parameters. Add(New SqlParameter("@ phone_nbr", SqlDbType.Char, 14))

cmd.Parameters. Add(New SqlParameter("@ email_address", SqlDbType.Char, 50))
cmd.Parameters. Add(New SqlParameter("@ login_status", SqlDbType.Bit))

cmd.Parameters. Add(New SqlParameter("@ credit_card_nam e", SqlDbType.Char,
27))

cmd.Parameters. Item("@username ").Value = RegUsrnameTXT.T ext

cmd.Parameters. Item("@fullname ").Value = RegFullnameTXT. Text

cmd.Parameters. Item("@password ").Value = RegPasswordTXT. Text

cmd.Parameters. Item("@credit_c ard_nbr").Value =

RegCreditcardnu mberTXT.Text

cmd.Parameters. Item("@credit_c ard_expiry_date ").Value =
RegCreditcardex piryTXT.Text

cmd.Parameters. Item("@mailing_ address").Value = RegAddressTXT.T ext

cmd.Parameters. Item("@email_ad dress").Value = RegEmailTXT.Tex t

cmd.Parameters. Item("@phone_nb r").Value = RegPhoneTXT.Tex t

cmd.Parameters. Item("@login_st atus").Value = 1

cmd.Parameters. Item("@credit_c ard_name").Valu e = RegCreditcardna meTXT.Text
'opent the connection to the database

dbConn.Open()

'execute sql statement

cmd.ExecuteNonQ uery()

dbConn.Close()

Catch objError As Exception

dberror.Text = "<b>* error while uploading original data</b>.<br />" &
objError.Messag e & objError.Source

Exit Sub

Finally

If dbConn.State = ConnectionState .Open Then

dbConn.Close()

End If

End Try

End Sub

End Class


--------------------------------------------------------------------------
--
---


Nov 20 '05 #9
here is the sql script to create the database, at the end is the procedure
im using.

i very much appreciate the help...

bryan

-----------------------------------------------------

CREATE TABLE BCustomerCA (
username char(19) NOT NULL,
fullname varchar(27) NULL,
credit_card_nbr char(18) NULL,
password char(7) NULL,
credit_card_exp iry_date datetime NULL,
mailing__addres s varchar(100) NULL,
phone_nbr char(14) NULL,
email_address char(50) NULL,
login_status bit NULL,
credit_card_nam e char(27) NULL
)
go
ALTER TABLE BCustomerCA
ADD PRIMARY KEY NONCLUSTERED (username)
go
CREATE TABLE BManufacturerCA (
manufacturer_id char(14) NOT NULL,
manufacturer_na me varchar(50) NULL,
email_address char(50) NULL,
contact_name varchar(27) NULL,
phone_nbr char(14) NULL
)
go
ALTER TABLE BManufacturerCA
ADD PRIMARY KEY NONCLUSTERED (manufacturer_i d)
go
CREATE TABLE BOrderItemCA (
part_id char(18) NOT NULL,
po_nbr char(18) NOT NULL,
item_qty int NULL
)
go
ALTER TABLE BOrderItemCA
ADD PRIMARY KEY NONCLUSTERED (part_id, po_nbr)
go
CREATE TABLE BPartCA (
part_id char(18) NOT NULL,
part_name varchar(50) NULL,
stock_size int NULL,
manufacturer_id char(14) NULL,
part_price decimal(10,2) NULL
)
go
ALTER TABLE BPartCA
ADD PRIMARY KEY NONCLUSTERED (part_id)
go
CREATE TABLE BPurchaseOrderC A (
po_nbr char(18) NOT NULL,
po_timetable datetime NULL,
isprocessed bit NULL,
username char(19) NULL
)
go
ALTER TABLE BPurchaseOrderC A
ADD PRIMARY KEY NONCLUSTERED (po_nbr)
go
CREATE TABLE BStaffCA (
username char(19) NOT NULL,
password char(7) NULL,
login_status bit NULL,
fullname varchar(27) NULL
)
go
ALTER TABLE BStaffCA
ADD PRIMARY KEY NONCLUSTERED (username)
go
ALTER TABLE BOrderItemCA
ADD FOREIGN KEY (po_nbr)
REFERENCES BPurchaseOrderC A
go
ALTER TABLE BOrderItemCA
ADD FOREIGN KEY (part_id)
REFERENCES BPartCA
go
ALTER TABLE BPartCA
ADD FOREIGN KEY (manufacturer_i d)
REFERENCES BManufacturerCA
go
ALTER TABLE BPurchaseOrderC A
ADD FOREIGN KEY (username)
REFERENCES BCustomerCA
go


create trigger tD_BCustomerCA on BCustomerCA for DELETE as
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* DELETE trigger on BCustomerCA */
begin
declare @errno int,
@errmsg varchar(255)
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BCustomerCA R/5 BPurchaseOrderC A ON PARENT DELETE SET NULL */
update BPurchaseOrderC A
set
/* BPurchaseOrderC A.username = NULL */
BPurchaseOrderC A.username = NULL
from BPurchaseOrderC A,deleted
where
/* BPurchaseOrderC A.username = deleted.usernam e */
BPurchaseOrderC A.username = deleted.usernam e
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go

create trigger tU_BCustomerCA on BCustomerCA for UPDATE as
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* UPDATE trigger on BCustomerCA */
begin
declare @numrows int,
@nullcnt int,
@validcnt int,
@insusername char(19),
@errno int,
@errmsg varchar(255)

select @numrows = @@rowcount
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BCustomerCA R/5 BPurchaseOrderC A ON PARENT UPDATE SET NULL */
if
/* update(username ) */
update(username )
begin
update BPurchaseOrderC A
set
/* BPurchaseOrderC A.username = NULL */
BPurchaseOrderC A.username = NULL
from BPurchaseOrderC A,deleted
where
/* BPurchaseOrderC A.username = deleted.usernam e */
BPurchaseOrderC A.username = deleted.usernam e
end
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go

create trigger tD_BManufacture rCA on BManufacturerCA for DELETE as
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* DELETE trigger on BManufacturerCA */
begin
declare @errno int,
@errmsg varchar(255)
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BManufacturerCA R/4 BPartCA ON PARENT DELETE SET NULL */
update BPartCA
set
/* BPartCA.manufac turer_id = NULL */
BPartCA.manufac turer_id = NULL
from BPartCA,deleted
where
/* BPartCA.manufac turer_id = deleted.manufac turer_id */
BPartCA.manufac turer_id = deleted.manufac turer_id
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go

create trigger tU_BManufacture rCA on BManufacturerCA for UPDATE as
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* UPDATE trigger on BManufacturerCA */
begin
declare @numrows int,
@nullcnt int,
@validcnt int,
@insmanufacture r_id char(14),
@errno int,
@errmsg varchar(255)

select @numrows = @@rowcount
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BManufacturerCA R/4 BPartCA ON PARENT UPDATE SET NULL */
if
/* update(manufact urer_id) */
update(manufact urer_id)
begin
update BPartCA
set
/* BPartCA.manufac turer_id = NULL */
BPartCA.manufac turer_id = NULL
from BPartCA,deleted
where
/* BPartCA.manufac turer_id = deleted.manufac turer_id */
BPartCA.manufac turer_id = deleted.manufac turer_id
end
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go

create trigger tI_BOrderItemCA on BOrderItemCA for INSERT as
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* INSERT trigger on BOrderItemCA */
begin
declare @numrows int,
@nullcnt int,
@validcnt int,
@errno int,
@errmsg varchar(255)

select @numrows = @@rowcount
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BPurchaseOrderC A R/3 BOrderItemCA ON CHILD INSERT RESTRICT */
if
/* update(po_nbr) */
update(po_nbr)
begin
select @nullcnt = 0
select @validcnt = count(*)
from inserted,BPurch aseOrderCA
where
/* inserted.po_nbr = BPurchaseOrderC A.po_nbr */
inserted.po_nbr = BPurchaseOrderC A.po_nbr
/* */

if @validcnt + @nullcnt != @numrows
begin
select @errno = 30002,
@errmsg = 'Cannot INSERT BOrderItemCA because BPurchaseOrderC A
does not exist.'
goto error
end
end

/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BPartCA R/2 BOrderItemCA ON CHILD INSERT RESTRICT */
if
/* update(part_id) */
update(part_id)
begin
select @nullcnt = 0
select @validcnt = count(*)
from inserted,BPartC A
where
/* inserted.part_i d = BPartCA.part_id */
inserted.part_i d = BPartCA.part_id
/* */

if @validcnt + @nullcnt != @numrows
begin
select @errno = 30002,
@errmsg = 'Cannot INSERT BOrderItemCA because BPartCA does not
exist.'
goto error
end
end
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go

create trigger tU_BOrderItemCA on BOrderItemCA for UPDATE as
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* UPDATE trigger on BOrderItemCA */
begin
declare @numrows int,
@nullcnt int,
@validcnt int,
@inspart_id char(18),
@inspo_nbr char(18),
@errno int,
@errmsg varchar(255)

select @numrows = @@rowcount
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BPurchaseOrderC A R/3 BOrderItemCA ON CHILD UPDATE RESTRICT */
if
/* update(po_nbr) */
update(po_nbr)
begin
select @nullcnt = 0
select @validcnt = count(*)
from inserted,BPurch aseOrderCA
where
/* inserted.po_nbr = BPurchaseOrderC A.po_nbr */
inserted.po_nbr = BPurchaseOrderC A.po_nbr
/* */

if @validcnt + @nullcnt != @numrows
begin
select @errno = 30007,
@errmsg = 'Cannot UPDATE BOrderItemCA because BPurchaseOrderC A
does not exist.'
goto error
end
end

/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BPartCA R/2 BOrderItemCA ON CHILD UPDATE RESTRICT */
if
/* update(part_id) */
update(part_id)
begin
select @nullcnt = 0
select @validcnt = count(*)
from inserted,BPartC A
where
/* inserted.part_i d = BPartCA.part_id */
inserted.part_i d = BPartCA.part_id
/* */

if @validcnt + @nullcnt != @numrows
begin
select @errno = 30007,
@errmsg = 'Cannot UPDATE BOrderItemCA because BPartCA does not
exist.'
goto error
end
end
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go

create trigger tD_BPartCA on BPartCA for DELETE as
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* DELETE trigger on BPartCA */
begin
declare @errno int,
@errmsg varchar(255)
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BPartCA R/2 BOrderItemCA ON PARENT DELETE RESTRICT */
if exists (
select * from deleted,BOrderI temCA
where
/* BOrderItemCA.pa rt_id = deleted.part_id */
BOrderItemCA.pa rt_id = deleted.part_id
)
begin
select @errno = 30001,
@errmsg = 'Cannot DELETE BPartCA because BOrderItemCA exists.'
goto error
end
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go

create trigger tI_BPartCA on BPartCA for INSERT as
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* INSERT trigger on BPartCA */
begin
declare @numrows int,
@nullcnt int,
@validcnt int,
@errno int,
@errmsg varchar(255)

select @numrows = @@rowcount
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BManufacturerCA R/4 BPartCA ON CHILD INSERT SET NULL */
if
/* update(manufact urer_id) */
update(manufact urer_id)
begin
update BPartCA
set
/* BPartCA.manufac turer_id = NULL */
BPartCA.manufac turer_id = NULL
from BPartCA,inserte d
where
/* */

not exists (
select * from BManufacturerCA
where
/* inserted.manufa cturer_id = BManufacturerCA .manufacturer_i d */
inserted.manufa cturer_id = BManufacturerCA .manufacturer_i d
)
end
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go

create trigger tU_BPartCA on BPartCA for UPDATE as
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* UPDATE trigger on BPartCA */
begin
declare @numrows int,
@nullcnt int,
@validcnt int,
@inspart_id char(18),
@errno int,
@errmsg varchar(255)

select @numrows = @@rowcount
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BPartCA R/2 BOrderItemCA ON PARENT UPDATE RESTRICT */
if
/* update(part_id) */
update(part_id)
begin
if exists (
select * from deleted,BOrderI temCA
where
/* BOrderItemCA.pa rt_id = deleted.part_id */
BOrderItemCA.pa rt_id = deleted.part_id
)
begin
select @errno = 30005,
@errmsg = 'Cannot UPDATE BPartCA because BOrderItemCA exists.'
goto error
end
end

/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BManufacturerCA R/4 BPartCA ON CHILD UPDATE SET NULL */
if
/* update(manufact urer_id) */
update(manufact urer_id)
begin
update BPartCA
set
/* BPartCA.manufac turer_id = NULL */
BPartCA.manufac turer_id = NULL
from BPartCA,inserte d
where
/* */

not exists (
select * from BManufacturerCA
where
/* inserted.manufa cturer_id = BManufacturerCA .manufacturer_i d */
inserted.manufa cturer_id = BManufacturerCA .manufacturer_i d
)
end
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go

create trigger tD_BPurchaseOrd erCA on BPurchaseOrderC A for DELETE as
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* DELETE trigger on BPurchaseOrderC A */
begin
declare @errno int,
@errmsg varchar(255)
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BPurchaseOrderC A R/3 BOrderItemCA ON PARENT DELETE RESTRICT */
if exists (
select * from deleted,BOrderI temCA
where
/* BOrderItemCA.po _nbr = deleted.po_nbr */
BOrderItemCA.po _nbr = deleted.po_nbr
)
begin
select @errno = 30001,
@errmsg = 'Cannot DELETE BPurchaseOrderC A because BOrderItemCA
exists.'
goto error
end
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go

create trigger tI_BPurchaseOrd erCA on BPurchaseOrderC A for INSERT as
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* INSERT trigger on BPurchaseOrderC A */
begin
declare @numrows int,
@nullcnt int,
@validcnt int,
@errno int,
@errmsg varchar(255)

select @numrows = @@rowcount
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BCustomerCA R/5 BPurchaseOrderC A ON CHILD INSERT SET NULL */
if
/* update(username ) */
update(username )
begin
update BPurchaseOrderC A
set
/* BPurchaseOrderC A.username = NULL */
BPurchaseOrderC A.username = NULL
from BPurchaseOrderC A,inserted
where
/* */

not exists (
select * from BCustomerCA
where
/* inserted.userna me = BCustomerCA.use rname */
inserted.userna me = BCustomerCA.use rname
)
end
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go

create trigger tU_BPurchaseOrd erCA on BPurchaseOrderC A for UPDATE as
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* UPDATE trigger on BPurchaseOrderC A */
begin
declare @numrows int,
@nullcnt int,
@validcnt int,
@inspo_nbr char(18),
@errno int,
@errmsg varchar(255)

select @numrows = @@rowcount
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BPurchaseOrderC A R/3 BOrderItemCA ON PARENT UPDATE RESTRICT */
if
/* update(po_nbr) */
update(po_nbr)
begin
if exists (
select * from deleted,BOrderI temCA
where
/* BOrderItemCA.po _nbr = deleted.po_nbr */
BOrderItemCA.po _nbr = deleted.po_nbr
)
begin
select @errno = 30005,
@errmsg = 'Cannot UPDATE BPurchaseOrderC A because BOrderItemCA
exists.'
goto error
end
end

/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
/* BCustomerCA R/5 BPurchaseOrderC A ON CHILD UPDATE SET NULL */
if
/* update(username ) */
update(username )
begin
update BPurchaseOrderC A
set
/* BPurchaseOrderC A.username = NULL */
BPurchaseOrderC A.username = NULL
from BPurchaseOrderC A,inserted
where
/* */

not exists (
select * from BCustomerCA
where
/* inserted.userna me = BCustomerCA.use rname */
inserted.userna me = BCustomerCA.use rname
)
end
/* ERwin Builtin Thu Jan 29 14:56:59 2004 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go
SET QUOTED_IDENTIFI ER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE PROCEDURE addCustomerSQL
(

@username char(19),
@fullname varchar(27),
@password char(7),
@credit_card_nb r char(18),
@credit_card_ex piry_date datetime,
@mailing_addres s varchar(100),
@phone_nbr char(14),
@email_address char(50),
@login_status bit,
@credit_card_na me char(27)

)
AS
INSERT INTO BCustomerCA VALUES (@username , @fullname, @password,
@credit_card_nb r, @credit_card_ex piry_date, @mailing_addres s, @phone_nbr,
@email_address, @login_status, @credit_card_na me )
GO

SET QUOTED_IDENTIFI ER OFF
GO

SET ANSI_NULLS ON
GO
----------------------------------------------------------
"William Ryan eMVP" <bi**@NoSp4m.de vbuzz.com> wrote in message
news:Or******** *******@TK2MSFT NGP12.phx.gbl.. .
Hmm, do you have any binary fields in the DB? I'm hesitant to admit this,
but I had this problem once and I realized I had defined a Varchar field to VarBinary and that was ultimately the cause.

Can you post the table script and the SQL Statement you are using? I'll be glad to create a table and give it a try...

Bill
"Bryan" <ca**********@r ogers.com> wrote in message
news:Ge******** ************@ne ws04.bloor.is.n et.cable.rogers .com...
I noticed that also, yet the datatypes are teh same in sql and in teh vb
code. this is driving me nuts.

thanks again.
bry
"William Ryan eMVP" <bi**@NoSp4m.de vbuzz.com> wrote in message
news:eA******** ******@TK2MSFTN GP11.phx.gbl...
Bryan:

What is the datatype of the field in SqlServer? Bit or Binary? The Param type is specified as Bit but by the Exception message, I'm wondering if it's
not Binary in the DB. If so, I believe changing the db type in the client code to SqlDbType.Binar y or changing the data type server side to Bit may
do
it for you.

HTH,

Bill
"Bryan" <ca**********@r ogers.com> wrote in message
news:5y******** ************@ne ws04.bloor.is.n et.cable.rogers .com...
> hello all...
>
> im trying to add a record to an sql db on ms sql server 2000, using
vb.net.
>
> seems to be working.. except for one thing, one of the columns in
the > database is a bit datatype, and though i get no syntax errors when
> compiling, i get an error indicated that the data would be truncated. the
> field is login_status.
>
> ive tried in quotes and not, giving it an integer variable with the

number
1
> in it, true/false statements.. ive tried a bunch of stuff... has me real > stumped..
>
> have any ideas?
>
> thanks
>
>
> here is the error it spits out.
>
> <b>* error while uploading original data</b>.<br />String or binary data > would be truncated.The statement has been terminated..Net SqlClient Data > Provider
>
>
>
>


--------------------------------------------------------------------------
> here is the code:


--------------------------------------------------------------------------
> Imports System.Data
>
> Imports System.Data.Sql Client
>
>
>
>
>
> Public Class WebForm1
>
> Inherits System.Web.UI.P age
>
>
>
>
>
>
>
>
>
>
> Public Sub Register_User(B yVal sender As Object, ByVal E As
EventArgs) >
> Dim dbConnStr As String = "user id=**(blanked for
> security)***;pa ssword=**(blank ed for
> security)**;dat abase=BCdb;serv er=localhost"
>
> Dim dbConn As New System.Data.Sql Client.SqlConne ction(dbConnStr )
>
>
>
>
>
>
>
> Try
>
> Dim cmd As New SqlCommand("add CustomerSQL", dbConn)
>
> cmd.CommandType = CommandType.Sto redProcedure
>
> cmd.Parameters. Add(New SqlParameter("@ username", SqlDbType.Char, 19)) >
> cmd.Parameters. Add(New SqlParameter("@ fullname", SqlDbType.VarCh ar,

27)) >
> cmd.Parameters. Add(New SqlParameter("@ password", SqlDbType.Char, 7))
>
> cmd.Parameters. Add(New SqlParameter("@ credit_card_nbr ", SqlDbType.Char, 18))
>
> cmd.Parameters. Add(New SqlParameter("@ credit_card_exp iry_date",
> SqlDbType.DateT ime))
>
> cmd.Parameters. Add(New SqlParameter("@ mailing_address ",

SqlDbType.VarCh ar,
> 100))
>
> cmd.Parameters. Add(New SqlParameter("@ phone_nbr", SqlDbType.Char, 14)) >
> cmd.Parameters. Add(New SqlParameter("@ email_address", SqlDbType.Char, 50))
>
> cmd.Parameters. Add(New SqlParameter("@ login_status", SqlDbType.Bit))
>
> cmd.Parameters. Add(New SqlParameter("@ credit_card_nam e", SqlDbType.Char, > 27))
>
> cmd.Parameters. Item("@username ").Value = RegUsrnameTXT.T ext
>
> cmd.Parameters. Item("@fullname ").Value = RegFullnameTXT. Text
>
> cmd.Parameters. Item("@password ").Value = RegPasswordTXT. Text
>
> cmd.Parameters. Item("@credit_c ard_nbr").Value =
RegCreditcardnu mberTXT.Text
>
> cmd.Parameters. Item("@credit_c ard_expiry_date ").Value =
> RegCreditcardex piryTXT.Text
>
> cmd.Parameters. Item("@mailing_ address").Value = RegAddressTXT.T ext
>
> cmd.Parameters. Item("@email_ad dress").Value = RegEmailTXT.Tex t
>
> cmd.Parameters. Item("@phone_nb r").Value = RegPhoneTXT.Tex t
>
> cmd.Parameters. Item("@login_st atus").Value = 1
>
> cmd.Parameters. Item("@credit_c ard_name").Valu e =

RegCreditcardna meTXT.Text
>
> 'opent the connection to the database
>
> dbConn.Open()
>
> 'execute sql statement
>
> cmd.ExecuteNonQ uery()
>
> dbConn.Close()
>
> Catch objError As Exception
>
> dberror.Text = "<b>* error while uploading original data</b>.<br />"
& > objError.Messag e & objError.Source
>
> Exit Sub
>
> Finally
>
> If dbConn.State = ConnectionState .Open Then
>
> dbConn.Close()
>
> End If
>
> End Try
>
> End Sub
>
>
>
> End Class
>


-------------------------------------------------------------------------- --
> ---
>
>
>



Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2410
by: Jamie Fryatt | last post by:
Hi everyone, here's what id like to do. I have a table with 2 fields, name and value I need to be able to add multiple records quickly, for example I need to add name value abc 1 abc 2 abc 3
2
5786
by: brenda.stow | last post by:
error msg " An error occured while referencing the object. You tried to run a visual basic procedure that improperly references a property or method of an object" This msg occurs everytime I add a new record to a subform. If I close msgbox I can then successfully add new record. Have looked on MS Technet and tried their 2 suggestions:- 1)LinkChildFields property contains the name of a form property - this isn't the case linkChildFields...
2
3638
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete a row. Everything works just fine. BUT I would like to add a button to (for example) the DataGrid header, which when pressed will add a new row to the datagrid. This should then allow the user to enter information into text boxes (in some...
3
4879
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
9
424
by: Greg | last post by:
Binding Manager & dataset - won't add record I've got an untyped dataset with controls bound through code. The user can select a question number from a bound combobox, and the question number and question text are displayed in bound textboxes. This part works fine. When I go to add a new record, the textboxes clear as they should. I enter a new question number and tab to the textbox for the question text. At this point, the text for the...
6
4427
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire row doesn't get filled. I have a connection and all that stuff. Private Sub btnPlaceBet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaceBet.Click ' Dim Myds As Footbet.DStable '...
8
3272
by: shumaker | last post by:
I'm wondering if adding an autonumber primary key will improve the performance of a multiuser access database on a network share. I have a website that lists many tips for improving performance of access, but doesn't mention primary keys. However, it seems logical to think that having no primary key means that when a user updates a record, the database has to do comparisons on multiple fields to identify the specific record being...
3
5350
by: john | last post by:
In my form (table A) I have subform (table B (only 2 fieds: ID and App_name) where table A -Table B are linked 1XM. To be able to add a record in the subform I want to use a lookup form since the number of possible values is over 300. For data consistancy I've locked the subform so that the user can't add or change values manually without using the lookup form. My question is: What's the best way of adding the record to table B which the...
1
1224
by: tonylove42 | last post by:
HI, I have probelm adding, updating and deleteing a record. Here is my code for adding . The error I get is: Operation must use an updateable query. Line 135: MyCmd.ExecuteNonQuery() I get same error for update and delete. here is my code for adding: MySQL = "INSERT INTO Property " & _ "(PropAddress, PropCity, PropSuburb, PropType, " & _
1
2636
by: ConfusedMay | last post by:
Hi, I'm working on a database that has a form which hold all of our products testing. each product can hold more than 1 complete test (complete test here means that product has to have before and after standard tests) This database is created in access 97. The form has 2 portion which is "before standard test" and "after standard test". What I need is when user does product test, user has to enter before and after standard tests textboxes....
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.