White spaces added in sql database RRS feed

  • Question

  • Hi,

    When I insert textbox data into SqlDatabase its autometic added blank white spaces in database. How i can remove it.

    here is my codes of insert..

    Kindly help

      Private Sub addbtn_Click(sender As Object, e As EventArgs) Handles addbtn.Click
            Dim insertQuery As String = "INSERT INTO vendorinfo (Code,Name,Gstn,State,Address,Email,Contact) VALUES(@code,@name,@gstn,@state,@add,@email,@con)"
            Dim cmd As New SqlCommand(insertQuery, con)
            If vennametxt.Text = "" Or vencodetxt.Text = "" Or vengsttxt.Text = "" Then
                MsgBox("Kindly Fill All    *   Mark Fields.")
                cmd.Parameters.Add("@code", SqlDbType.NChar).Value = vencodetxt.Text.ToString
                cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = vennametxt.Text.Trim.ToString
                cmd.Parameters.Add("@gstn", SqlDbType.NVarChar).Value = vengsttxt.Text.ToString
                cmd.Parameters.Add("@state", SqlDbType.NChar).Value = venstatetxt.Text.ToString
                cmd.Parameters.Add("@add", SqlDbType.NChar).Value = venaddtxt.Text.Trim '.ToString
                cmd.Parameters.Add("@email", SqlDbType.NChar).Value = venemailtxt.Text
                cmd.Parameters.Add("@con", SqlDbType.BigInt).Value = Convert.ToInt64(vencontxt.Text) '.ToString
                MessageBox.Show("Vendor Added Successfully", "E-Sol Billing Software", MessageBoxButtons.OK)
            End If
            Dim loadQuery As String = "select * from vendorinfo"
            Dim cmd1 As New SqlCommand(loadQuery, con)
            Dim da As New SqlDataAdapter(cmd1)
            Dim dt As New DataTable
            DataGridView1.DataSource = dt
        End Sub

    Monday, October 1, 2018 5:30 AM


  • Try changing the type of the columns (in database) from, for example, ‘nchar(20)’ to ‘nvarchar(20)’.

    • Marked as answer by kachani_anil Monday, October 1, 2018 6:34 AM
    Monday, October 1, 2018 5:45 AM