What error I have in the following simple CODE ?

DewC

New member
Joined
Aug 11, 2004
Messages
1
Programming Experience
Beginner
Sub UpdateDBdata(ByVal docID As String, ByVal Revision As String)
Try
Dim connection As New SqlConnection("Server=it; Initial Catalog=qs; User ID=sa; pwd=sqldata")
Dim command As New SqlCommand("UpdateRev", connection)
command.CommandType = CommandType.StoredProcedure

Dim param_Revision As SqlParameter
param_Revision = command.Parameters.Add("@Rev_n", SqlDbType.Char, 6)
param_Revision.Value = "REVVV"
Dim param_ID As SqlParameter
param_ID = command.Parameters.Add("@DocID", SqlDbType.Int)
param_ID.Value = docID

connection.Open()
command.ExecuteNonQuery()
connection.Close()

Catch ex As Exception
checkError.Text = ex.ToString()
checkError.Visible = True
End Try
End Sub


The Debugger shows error:


System.FormatException: Input string was not in a correct format. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Test.Grid.UpdateDBdata(String docID, String Revision) in C:\Inetpub\wwwroot\Test\Grid.aspx.vb:line 140
 
Try using a varchar type instead of a char(6), this may be good for your DB as well.

You have to keep in mind that the types have to match between paramater and DB. Also, the char type is exactly size 6, any string that is less, it pads the char parameter with "white space", any thing more, it cuts the string off.
 
Back
Top