I am newbie to vb.net. I am trying to save data to database
but I got a exception
here is the code
Try 'connection is set
sqlcon = New SqlConnection("Data Source=MENUKA-PC\SQLEXPRESS;Initial Catalog=studentInformation; Integrated Security=True")
sqlcon.Open()
sqlcommand = New SqlCommand() 'Once we have an instance of this object we need to set some of its properties
sqlcommand.Connection = sqlcon
' You'll have to set the SqlCommand's "CommandText" property
'to be the SQL commands that need to be carried out by
'the function you're creating.
sqlcommand.CommandType = CommandType.Text
sqlcommand.CommandText = "INSERT INTO stuDetails(stuReg, stuFullName,stuInitials,stuAddress,stuContact1,stuContact2,stuBday,stuMale,stuFemale) VALUES(@stuReg, @stuFullName,@stuInitials,@stuAddress,@stuContact1,@stuContact2,@stuBday,@stuMale,@stuFemale)"
' sqlcommand.Parameters.Add("@cID", SqlDbType.Int).Value = 1234567
sqlcommand.Parameters.Add("@stuReg", SqlDbType.VarChar).Value = txtRegNo.Text.ToString
sqlcommand.Parameters.Add("@stuFullName", SqlDbType.VarChar).Value = txtNameFull.Text.ToString
sqlcommand.Parameters.Add("@stuInitials", SqlDbType.VarChar).Value = txtNameInitals.Text.ToString
sqlcommand.Parameters.Add("@stuAddress", SqlDbType.VarChar).Value = txtAddress.Text.ToString
sqlcommand.Parameters.Add("@stuContact1", SqlDbType.VarChar).Value = txtContact1.Text.ToString
sqlcommand.Parameters.Add("@stuContact2", SqlDbType.VarChar).Value = txtContact2.Text.ToString
sqlcommand.Parameters.Add("@stuBday", SqlDbType.VarChar).Value = DateTimePicker1.Text.ToString
sqlcommand.Parameters.Add("@stuMale", SqlDbType.VarChar).Value = rdbMale.Text.ToString
sqlcommand.Parameters.Add("@stuFemale", SqlDbType.VarChar).Value = rdbFemale.Text.ToString
sqlcommand.ExecuteNonQuery()
MsgBox("Data submit succesfully")
sqlcon.Close()
Catch ex As Exception
MsgBox("exceprion " + ex.Message)
End Try
I think problem is in the radio buttons. radiobutton.value is not working in vb.net though worked in vb6
so I set rdbButton.text . I am not sure about that. How ever I got the following exception
"String or binary data would be truncated the statement has been terminated"
here is the database query
--create table stuDetails( --id int identity not null, --stuReg varchar(7), --stuFullName varchar(100), --stuInitials varchar (50), --stuAddress varchar (200), --stuContact1 varchar (10), --stuContact2 varchar (10), --stuBday varchar (10), --stuMale varchar (5), --stuFemale varchar (5))
plz help me
thx in advance,
Menuka.
This post has been edited by menukadevinda: 10 October 2011 - 10:15 PM

New Topic/Question
Reply



MultiQuote





|