Results 1 to 5 of 5

Thread: [RESOLVED] DataTable.Rows.Add Error

  1. #1

    Thread Starter
    Addicted Member scsfdev's Avatar
    Join Date
    Feb 2008
    Location
    Singapore
    Posts
    224

    Resolved [RESOLVED] DataTable.Rows.Add Error

    Hi all,

    I am facing below problem. Your help is really appreciated.

    Cannot perform '=' operation on System.Int32 and System.String.

    What I tried to do here is I have a dataset get from SQL Express 2005 and I am adding a new row to it and it hit the above error.

    I combine 3 tables in SQL and return the data to my win application.
    And I add 1 row to it.

    Here is the data type in my sql statement.

    Code:
    SELECT cd.indexNo, c.custid, c.companyname, c.contactperson, c.contactno,
    dt.Type, cdm.DrawingMaterial, cd.Size, cd.Roundness
    FROM rpts_customer As c, rpts_custdiesdetail As cd, 
    rpts_Type As dt, rpts_CustDrawMaterial As cdm
    WHERE c.custID = cd.custID AND
    cd.cdmNo = cdm.cdmNo AND
    cd.dtNo = dt.dtNo AND
    c.Active = 'TRUE'
    ORDER BY dt.Type
    
    indexNo = Integer (which is an auto increasement column in master table)
    custID = Integer (same as indexNo, auto increase)
    companyName = VarChar(50)
    contactperson = VarChar(50)
    contactno = VarChar(50)
    Type = VarChar(50)
    DrawingMaterial = VarChar(50)
    Size = Numeric(10,6)
    Roundness = Numeric(10,6)
    
    dtNo = Int (auto increase)
    cdmNo = Int (auto increase)
    Active = Bit
    And Here is my code in vb.net
    VB.Net Code:
    1. Dim dRow As DataRow = dSet.Tables("tblCustDetail").NewRow
    2. dRow.Item(DBFN_IndexNo) = 1
    3. dRow.Item(DBFN_CustID) = txtCustID.Text.Trim
    4. dRow.Item(DBFN_CompanyName) = txtCompanyName.Text.Trim
    5. dRow.Item(DBFN_ContactPerson) = txtContactPerson.Text.Trim
    6. dRow.Item(DBFN_ContactNo) = txtContact.Text.Trim
    7. dRow.Item(DBFN_Type) = cboType.Text
    8. dRow.Item(DBFN_DrawingMaterial) = cboDrawingMaterial.Text
    9. dRow.Item(DBFN_Size) = txtSize.Text.Trim
    10. dRow.Item(DBFN_Roundness) = txtRoundness.Text.Trim
    11.  
    12. dSet.Tables("tblCustDetail").Rows.Add(dRow)

    Anybody has any idea???
    I'm out of solution. I checked the Database fields and its the same. No differences.
    I don't know what should I do...

    Help..

    Thanks.
    scsfdev
    I'm using VS 2005 & 2008 & 2010 with SQL Server 2005 Express.

    My hobby beside programming: http://dslrstranger.wordpress.com

  2. #2
    Hyperactive Member Chathura's Avatar
    Join Date
    Nov 2005
    Location
    Sri Lanka
    Posts
    345

    Re: DataTable.Rows.Add Error

    what's the problem here? Error message?
    If the post is heplful, Please Rate it
    Chathura Wijekoon

  3. #3
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: DataTable.Rows.Add Error

    There is no need to set the values for the auto increment column. Remove this

    Code:
    dRow.Item(DBFN_IndexNo) = 1
    dRow.Item(DBFN_CustID) = txtCustID.Text.Trim
    Please mark you thread resolved using the Thread Tools as shown

  4. #4
    Member
    Join Date
    Nov 2009
    Posts
    55

    Re: DataTable.Rows.Add Error

    Have you inserted this at the end?

    Code:
            da.Update(dSet)
            dSet.AcceptChanges()
    Where da is your dataadaptor. and you should have your insert commands as well.

    as in here http://www.vbforums.com/showthread.php?t=466658
    Last edited by reezan; Nov 25th, 2009 at 12:41 AM.

  5. #5

    Thread Starter
    Addicted Member scsfdev's Avatar
    Join Date
    Feb 2008
    Location
    Singapore
    Posts
    224

    Re: DataTable.Rows.Add Error

    Quote Originally Posted by Chathura View Post
    what's the problem here? Error message?
    Hi chathra,
    I'm finding the correct way of adding a new row.

    Quote Originally Posted by reezan View Post
    Have you inserted this at the end?

    Code:
            da.Update(dSet)
            dSet.AcceptChanges()
    Where da is your dataadaptor. and you should have your insert commands as well.

    as in here http://www.vbforums.com/showthread.php?t=466658
    Hi reezan,
    Thanks for your info. The problem is I don't even get to this" Update" stage. I'm stuck at "Add Row".

    Quote Originally Posted by danasegarane View Post
    There is no need to set the values for the auto increment column. Remove this

    Code:
    dRow.Item(DBFN_IndexNo) = 1
    dRow.Item(DBFN_CustID) = txtCustID.Text.Trim
    Hi danasegarane,

    You solution solve my issue.
    At first I only remove IndexNo but not tested with removing CustID field.
    After I remove this CustID field, it's working!!!

    thank you so much.
    ***********************
    One thing strange is now i can keep IndexNo and remove CustID, it will pass. If i keep both or keep IndexNO and remove CustID, it will fail like above error message.

    Any idea of why???
    actually in my Customer Detail table, this custID is dummy field. and IndexNo is its identity key and auto increase one.
    This custID is Identity key at customer table and set auto increase one.

    I wonder what is the theory behind this DataTable.Row.Add related to this database field constraints.

    Thanks for all.
    I'm using VS 2005 & 2008 & 2010 with SQL Server 2005 Express.

    My hobby beside programming: http://dslrstranger.wordpress.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width