Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this my table creating query

SQLFcmd.CommandText = " CREATE TABLE [dbo].[Assets] ([AssetID][nvarchar](50) NULL,[AssetBarcode][nvarchar](50) NULL,[AssetName][nvarchar](50) NULL,[AssetType][nvarchar](50) NOT NULL,[AssetDesc][nvarchar](50) NULL,[Store][nvarchar](50) NULL,[AssetLocation][nvarchar](75) NULL,[Manufacture][nvarchar](50) NULL,[Brand][nvarchar](50) NULL,[Model][nvarchar](50) NULL,[AssetMore][nvarchar](50) NULL,[AssetSNo][nvarchar](50) NULL,[AssetTotal][nvarchar](50) NULL,[PhotoPath][nvarchar](50) NULL,[Status][nvarchar](10) NULL,[Condition][nvarchar](10) NULL,[AssetExpiry][Datetime]NULL,[AssetNotes][nvarchar](100) NULL,[AssetVendor][nvarchar](50) NULL,[AssetPurRate][float](10) NULL,[AssetScrap][nvarchar](50) NULL,[AssetYear][varchar](10) NULL,[AssetPurDate][Datetime] NULL,[AssetServiceStartDate][Datetime] NULL,[AssetWarranty][Datetime] NULL,[AssetDepreciation][nvarchar](50) NULL,[AssetDepreciationRate][nvarchar](50) NULL)ON [PRIMARY] "
               SQLFcmd.CommandType = CommandType.Text
               SQLFcmd.ExecuteNonQuery()



now this my inserting query

MainForm.Cursor = Cursors.WaitCursor
       Dim SqlStr As String = ""

       'If IsOpenForAlter = True Then
       SqlStr = "UPDATE Assets SET [dbo].[AssetID]=@AssetID [AssetBarcode]=@AssetBarcode,[AssetName]=@AssetName,[AssetType]=@AssetType,[AssetDesc]=@AssetDesc,[Store]=@Store,[AssetLocation]=@AssetLocation,[Manufacture]=@Manufacture,[Brand]=@Brand,[Model]=@Model,[AssetMore]=@AssetMore,[AssetSNo]=@AssetSNo,[AssetTotal]=@AssetTotal,[PhotoPath]=@PhotoPath,[Status]=@Status,[Condition]=@Condition,[AssetExpiry]=@AssetExpiry,[AssetNotes]=@AssetNotes,[AssetVendor]=@AssetVendor,[AssetPurRate]=@AssetPurRate,[AssetScrap]=@AssetScrap,[AssetYear]=@AssetYear,[AssetPurDate]=@AssetPurDate,[AssetServiceStartDate]=@AssetServiceStartDate,[AssetWarranty]=@AssetWarranty,[AssetDepreciation]=@AssetDepreciation,[AssetDepreciationRate]=@AssetDepreciationRate, WHERE AssetName=N'" & OpenedAssetName & "'"
       'Else
       SqlStr = "INSERT INTO [dbo].[Assets] ([AssetID],[AssetBarcode],[AssetName],[AssetType],[AssetDesc],[Store],[AssetLocation],[Manufacture],[Brand],[Model],[AssetMore],[AssetSNo],[AssetTotal],[PhotoPath],[Status],[Condition],[AssetExpiry],[AssetNotes],[AssetVendor],[AssetPurRate],[AssetScrap],[AssetYear],[AssetPurDate],[AssetServiceStartDate],[AssetWarranty],[AssetDepreciation],[AssetDepreciationRate])     VALUES " _
    & " (@AssetID,@AssetBarcode,@AssetName,@AssetType,@AssetDesc,@Store,@AssetLocation,@Manufacture,@Brand,@Model,@AssetMore,@AssetSNo,@AssetTotal,@PhotoPath,@Status,@Condition,@AssetExpiry,@AssetNotes,@AssetVendor,@AssetPurRate,@AssetScrap,@AssetYear,@AssetPurDate,@AssetServiceStartDate,@AssetWarranty,@AssetDepreciation,@AssetDepreciationRate) "

       'End If
       Try
           MAINCON.ConnectionString = ConnectionStrinG
           MAINCON.Open()
           Dim DBF As New SqlClient.SqlCommand(SqlStr, MAINCON)
           With DBF.Parameters

               ' If Integer.TryParse(TxtAssetID.Text, id) Then
               'DBF.Parameters.AddWithValue("@AssetID", id)
               'Else
               '' The text in the textbox was not a valid integer representation.
               '' You may have to handle that case here.
               'End If
               .AddWithValue("@AssetID", TxtAssetID.Text)
               .AddWithValue("@AssetBarcode", TxtAssetBarcode.Text)
               .AddWithValue("@AssetName", TxtAssetName.Text)
               .AddWithValue("@AssetType", TxtAssetType.Text)
               .AddWithValue("@AssetDesc", TxtDescr.Text)
               .AddWithValue("@Store", TxtStoreName.Text)
               .AddWithValue("@AssetLocation", TxtLocation.Text)
               .AddWithValue("@Manufacture", TxtManufacture.Text)
               .AddWithValue("@Brand", TxtBrand.Text)
               .AddWithValue("@Model", TxtModel.Text)
               .AddWithValue("@AssetMore", TxtMoreInfo.Text)
               .AddWithValue("@AssetSNo", TxtSerialNumber.Text)
               .AddWithValue("@AssetTotal", TxtQty.Text)
               .AddWithValue("@PhotoPath", PhotoPathForLedgers & "\Others\" & TxtAssetName.Text & ".jpg")
               .AddWithValue("@Status", TxtAssetStatus.Text)
               .AddWithValue("@Condition", txtCondition.Text)
               .AddWithValue("AssetExpiry", TxtExpiry.Value)
               .AddWithValue("@AssetNotes", TxtNote.Text)

               .AddWithValue("@AssetVendor", TxtVendorName.Text)
               .AddWithValue("@AssetPurRate", TxtPurRate.Text)
               .AddWithValue("@AssetScrap", TxtScrapValue.Text)
               .AddWithValue("@AssetYear", TxtYears.Text)
               .AddWithValue("@AssetPurDate", TxtpurchaseDate.Value)
               .AddWithValue("@AssetServiceStartDate", TxtServiceStartDate.Value)
               .AddWithValue("@AssetWarranty", TxtWarrantyDate.Value)
               .AddWithValue("@AssetDepreciation", TxtDepreMethod.Text)
               .AddWithValue("@AssetDepreciationRate", TxtDepRate.Text)


           End With
           DBF.ExecuteNonQuery()
           DBF = Nothing
           MAINCON.Close()
       Catch ex As Exception
           MsgBox(ex.Message)
       End Try

       Dim OpenedID As Integer = 1
       Dim cnn As SqlConnection
       cnn = New SqlConnection(ConnectionStrinG)
       cnn.Open()
       Dim ds As New DataSet()
       MainForm.Cursor = Cursors.WaitCursor


What I have tried:

i have changed length to 255 but the same error occurs ,any one please help thanks in advance
Posted
Updated 3-Aug-18 8:41am
Comments
CHill60 3-Aug-18 14:24pm    
Changed which length? Only you know what is in the variables

1 solution

Quote:
any one please help thanks in advance

The question is impossible to answer because it is with your data.
The only possible advice is to use the debugger, put a breakpoint on line of error and check the value of each parameter against its matching field.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

The downside of this solution:
- It is a DIY, you are the one tracking the problem and finding its roots, which lead to the solution.
The upside of this solution:
- It is also a great learning tool because it show you reality and you can see which expectation match reality.

secondary effects
- Your will be proud of finding bugs yourself.
- Your learning skills will improve.

You should find pretty quickly what is wrong.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
Visual Basic / Visual Studio Video Tutorial - Basic Debugging - YouTube[^]
Visual Basic .NET programming for Beginners - Breakpoints and Debugging Tools[^]
The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900