Question Insert value plus Blanks in the end

mac-duff

Member
Joined
Dec 21, 2009
Messages
24
Programming Experience
Beginner
Hello,

I am having following problem. When I write Data to a database it every time fills the end of the field with blanks. The Textbox in Vb.Net seems to be ok but after I refreshed it I have all the blanks, in the MS-SQL server too.

To write the data I use the SQLConnection and later use the "Insert" command.

It would I guess also be helpfull when some tells me for what to I have to search in google because my result doesnt hit.

Thanks
Stephan
 
i would like to see the code and if you could tell me the data types of your sql fields that would be useful, but at a guess.
I am guessing you data types of your fields are chars. Try changing them to varchars and let me know if that helps.
 
HI,
thanks for the reply.

below u find my code but now I changed the char from n to v as u said and it seems to work fine.

Thx

VB.NET:
Expand Collapse Copy
Dim sqlConn As New SqlConnection("server=server;database=SHF;Integrated Security=True")
sqlConn.Open()
            Dim Gamastr = "Insert into Gamas (IdGama,NombreGama,NumModificacion,DescModificacion,Activa,Proyecto,IdCarro,IdMaquina,Fecha,tRegAuto,ControlPotencia,PotenciaSold,RetardoInicio,TiempoSold,TiempoEnfr,TiempoSubida,PosicionInicial,CorrienteSoldadura,PresionSoldadura,PresionEnfriamiento,TempPiovan,PosicionPrensa,NumMoldes,Utillaje,Portapiezas,Plancha,Observaciones) VALUES ('" & ComboBox_IDGama.Text & "','" & TextBox_NombreGama.Text & "','" & ComboBox_NumModificacion.Text & "','" & TextBox_DescModificacion.Text & "','" & CheckBox_Activa.CheckState & "','" & TextBox_Proyecto.Text & "','" & IdCarro_str & "','" & TextBox_IdMaquina.Text & "','" & DateTimePicker_Fecha.Text & "','" & tRegAuto_str & "','" & ControlPotencia_str & "','" & PotenciaSold_str & "','" & TextBox_RetardoInicio.Text & "','" & TextBox_TiempoSold.Text & "','" & TextBox_TiempoEnfr.Text & "','" & TextBox_TiempoSubida.Text & "','" & TextBox_PosicionInicial.Text & "','" & TextBox_CorrienteSoldadura.Text & "','" & TextBox_PresionSoldadura.Text & "','" & TextBox_PresionEnfriamiento.Text & "','" & TextBox_TempPiovan.Text & "','" & TextBox_PosicionPrensa.Text & "','" & TextBox_NumMoldes.Text & "','" & TextBox_Utillaje.Text & "','" & TextBox_Portapiezas.Text & "','" & TextBox_Plancha.Text & "','" & TextBox_Observaciones.Text & "')"
            Dim sqlInsert As SqlCommand = New SqlCommand(Gamastr, sqlConn)
Dim ra As Integer = sqlInsert.ExecuteNonQuery()
sqlConn.Close()
 
I'm with R3plica on this one.

It sounds like you have the fields set as Char(xxx).

Lets take an example.

You have Activa as Char(100). This means that field can be 100 characters max. (100 bytes)

In the textbox that inserts to that field, you've typed "yes". That's 3 characters. The field will create 97 spaces after what you have entered to make it up to the 100.

By setting fields as varChar(100) it means "variable". Therefore your maximum can still be 100 characters (and bytes) but if you only type "yes" in the field, it will only use 3 characters (and bytes)

A good explaination can be found here: char and varchar (Transact-SQL)
 
Back
Top