4 Replies - 1555 Views - Last Post: 02 March 2012 - 08:33 AM Rate Topic: -----

#1 farhan_b  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 133
  • Joined: 26-February 12

Field cannot be a zero-length string

Posted 02 March 2012 - 08:18 AM

i had the code belowing workin fine before but all of a suden i have a error init please can you tell me what i need to do please

     connect()
    End Sub
    Sub connect()
        acsconn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;data source=C:\Users\HP Sajad\Documents\Visual Studio 2010\Projects\login1\login1\security.mdb"
        acsconn.Open()
        If acsconn.State = ConnectionState.Open Then
            MsgBox("Connected")

        Dim strsql As String = "Insert into cg_security_user (user_name,user_pwd) values (@field1,@field2) "

        Dim objcmd As New System.Data.OleDb.OleDbCommand(strsql, acsconn) ' the oledbcommand

        With objcmd
            .Parameters.AddWithValue("@field1", txtname.Text)
            .Parameters.AddWithValue("@field2", txtpass.Text)
         
        End With
        objcmd.ExecuteNonQuery()
        objcmd.Dispose()
        MsgBox("Saved")

        End If
        acsconn.Close()



the error i get is Field 'cg_security_user.user_name' cannot be a zero-length string.

why is this

please help thank you

This post has been edited by Atli: 02 March 2012 - 08:31 AM
Reason for edit:: Updated the thread title. Please use meaningful titles for you posts. Something that tells us what it's about.


Is This A Good Question/Topic? 0
  • +

Replies To: Field cannot be a zero-length string

#2 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 204
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Field cannot be a zero-length string

Posted 02 March 2012 - 08:24 AM

Are you sure you're inserting a value for the field user_name?? I haven't worked with Access so without me saying anything more, here is a way to sort out this issue.

And please post your questions with meaningful titles.

This post has been edited by nK0de: 02 March 2012 - 08:25 AM

Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Field cannot be a zero-length string

Posted 02 March 2012 - 08:26 AM

Are you actually reading what the error message says or do you just pop in here when you get an error and post it?

User_name cannot be zero-length...
User_name cannot be empty...
User_name must contain something...

Why is it empty?

Do you want to allow it to be empty?

If you want to allow it to be empty then tell the database that it can be empty.
Was This Post Helpful? 0
  • +
  • -

#4 farhan_b  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 133
  • Joined: 26-February 12

Re: Field cannot be a zero-length string

Posted 02 March 2012 - 08:28 AM

when i enter details into the fields txtuser and txtpass
the error occurs in a box highlighting objcmd.ExecuteNonQuery
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Field cannot be a zero-length string

Posted 02 March 2012 - 08:33 AM

So when it crashes, and you put your mouse on txtuser.text what does it show is there?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1