|
[code]Public Function reverse(ByVal n As Integer) As Integer
Dim str As String = n.ToString
Dim temp As String = ""
For i As Integer = str.Length - 1 To 0 Step -1
temp += str.Chars(i)
Next
Return Integer.Parse(temp)
End Function[/code]
|
|
|
|
|
[code]Public Function clean(ByVal str1 As String, ByVal str2 As String) As String
Dim temp As String = ""
Dim f As Boolean
For i As Integer = 0 To str1.Length - 1
f = True
For j As Integer = 0 To str2.Length - 1
If str1.Chars(i) = str2.Chars(j) Then
f = False
End If
Next
If f Then
temp += str1.Chars(i)
End If
Next
Return temp
End Function
[/code]
|
|
|
|
|
You forgot to ask a question.
---
b { font-weight: normal; }
|
|
|
|
|
I guess I thought it would be easy to update a table, but evidently my code is incorrect.
This code keeps producing this error:
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.
whenever I make a change in the table and then press button1.
could anyone please explain why?
tia
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TickersTableAdapter.Fill(Me.DataSet1.Tickers)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.TickersTableAdapter.Update(Me.DataSet1.Tickers)
Me.DataSet1.AcceptChanges()
End Sub
End Class
|
|
|
|
|
hii
One simple way to solve this problem is to add atleast one record in the data base as you aspect it to be. or else just try to fill the primary record of the table with your value.
just try it and reply
bye
Nikhil Bandekar
Mumbai,
India
|
|
|
|
|
Hi Nikhil:
Yes, you are right that if I add a new row to the table then everything is OK. But how can update the table WITHOUT adding a new row?
thanks!
|
|
|
|
|
What does your SELECT SQL statement look like? Does it return a Primary Key column? (BTW: This is a MUST HAVE!) What does the UPDATE SQL statement look like or are you using a CommandBuilder to generate it?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks Dave, that was the problem. The table had no primary key!
Happy weekend!
chuck
|
|
|
|
|
...but why couldn't the error message say something like "table has no primary key!" or "$%()*&$)(*&%)(*#&$ (stuff that I can't understand): this error might be caused if the table has no primary key"
Just a thought...
BTW, I love vb.net despite these small issues. Didn't Gates say something about betting the company on .net. It's a good bet assuming there's enough people out there still writing code!
c
|
|
|
|
|
Because there's about a dozen reasons why an Update would affect 0 records. The problem has nothing to do with VB.NET. ADO.NET is what is reporting the error back to your code, but even then, it can't possibly know what caused it. It's just the SQL statement that failed, in the context of the database that it was used.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
My application was tested and almost ready to go to production, but seems to have gone wacky in the past day or two. Nothing seems to work correctly. I put a breakpoint into the program and during debugging VS came up with a message box "The source file has changed. It no longer matches the version of the file used to build the application being debugged.".
The only changes I've made the past few days were touchups to stored procedures that were renamed when we put them into production. I've tinkered around with the versioning with the publish feature.
Did I goof something up??? Has anyone encountered this error before, and if so, how did you fix your app???
Lost in the vast sea of .NET
|
|
|
|
|
Yes i have also observed this issue many times. The solution worked for me is in the Solution Explorer, Right Click your project solution and click rebuild solution.
Hope this helps
Mubashir
|
|
|
|
|
I think I might be able to help you I have also made this same mistake.
I accidently renamed the file outside vb.net eg (I went into mydocuments/ visual studios) and then i renamed the application i was developing. So visual basic .net could not find the file to save to. when you try to create a new program have you noticed that you have to create a name for it well when you do this it creates a file in your directory where all your programs are saved when they are in the development phase. The way to fix this is to either go back and change the file to it's orignal file name(the easiest way) or you will either have to restart creating it or you could try save as which might allow you to create another folder for the program you are developing.
I hope this helps
Ps I am sorry if this doesn't apply to youre problem.
|
|
|
|
|
Thanks for everyone's feedback. I didn't change the name of my project and the error eventually went away and I don't have a clue what I did wrong in the first place, or what I did to fix it.
My project is working fine now. Something was out of whack, but now it is working without a problem. If the problem comes up again, I'll keep your suggestions in mind.
Thanks!!!
Lost in the vast sea of .NET
|
|
|
|
|
i have a question:
how to make sorting when the user clicks on the header of a listview
i made a list view of many columns but i want to make sorting of the data by columns
when he clicks the header of column i - the data in the listview should be sorted by this column - i.
|
|
|
|
|
Here is a class to sort a listview. Just pass the index of the column and the listview when creating a new instance of the class.
Public Class CompareListViewItems
Implements IComparer
Shared bSortDirection As Boolean = True
Dim sRoutineToUse As String = "String"
Dim lView As ListView 'the listview in question
Dim iColumn As Integer 'the column to sort
Dim lvCollection As ListView.ListViewItemCollection
Dim bSafeToSort As Boolean = False
Sub New(ByVal itemIndex As Integer, ByVal lvListView As ListView)
iColumn = itemIndex
lView = lvListView
bSortDirection = Not bSortDirection
lvCollection = New ListView.ListViewItemCollection(lvListView)
determineType()
End Sub
Private Function determineType() As Boolean
'There needs to be at least 2 elements to sort --
If (lView.Items.Count < 2) Then
bSafeToSort = False
Return False
End If
'If a value is Null, a subitem might not be added
If (checkForNull() = True) Then
bSafeToSort = False
Return False
End If
'If there are values in each element, lets determine the type
If (isItADate() = True) Then
sRoutineToUse = "Date"
ElseIf (isItANumber() = True) Then
sRoutineToUse = "Number"
Else
sRoutineToUse = "String"
End If
End Function
Private Function checkForNull() As Boolean
Dim lvTest As ListViewItem
Dim sItemContents As String
For Each lvTest In lvCollection
Try
If iColumn = 0 Then
sItemContents = lvTest.Text
Else
sItemContents = lvTest.SubItems(iColumn).Text
End If
Catch
Return True
End Try
Next
bSafeToSort = True
Return False 'we are good to go
End Function
Private Function isItADate() As Boolean
'-- Is it a date? --
Dim lvTest As ListViewItem 'assigned a new row
Dim oObjectToTest As Object 'recipient of the assignment
Dim sItemContents As String 'contents of the element
'-- Loop through each element
For Each lvTest In lvCollection
If iColumn = 0 Then
sItemContents = lvTest.Text
Else
sItemContents = lvTest.SubItems(iColumn).Text
End If
Try
oObjectToTest = CDate(sItemContents)
Catch
Return False
End Try
Next
Return True
End Function
Private Function isItANumber() As Boolean
Dim lvTest As ListViewItem 'assigned a new row
Dim oObjectToTest As Object 'recipient of the assignment
Dim sItemContents As String 'contents of the element
'-- Loop through each element
For Each lvTest In lvCollection
If iColumn = 0 Then
sItemContents = lvTest.Text
Else
sItemContents = lvTest.SubItems(iColumn).Text
End If
Try
oObjectToTest = CDbl(sItemContents)
Catch
Return False
End Try
Next
Return True
End Function
Function compare(ByVal oFirst As Object, ByVal oSecond As Object) As Integer _
Implements System.Collections.IComparer.Compare
If bSafeToSort = False Then Exit Function
Dim lvElement1 As ListViewItem = CType(oFirst, ListViewItem)
Dim lvElement2 As ListViewItem = CType(oSecond, ListViewItem)
If sRoutineToUse = "String" Then
If bSortDirection = True Then
If iColumn = 0 Then
Return String.Compare(lvElement1.Text, lvElement2.Text)
Else
Return String.Compare(lvElement1.SubItems(iColumn).Text, _
lvElement2.SubItems(iColumn).Text)
End If
Else
If iColumn = 0 Then
Return String.Compare(lvElement2.Text, lvElement1.Text)
Else
Return String.Compare(lvElement2.SubItems(iColumn).Text, _
lvElement1.SubItems(iColumn).Text)
End If
End If
ElseIf sRoutineToUse = "Number" Then
If bSortDirection = True Then
If iColumn = 0 Then
Return Math.Sign(CLng(lvElement1.Text - lvElement2.Text))
Else
Return Math.Sign(CLng(lvElement1.SubItems(iColumn).Text _
- lvElement2.SubItems(iColumn).Text))
End If
Else
If iColumn = 0 Then
Return Math.Sign(CLng(lvElement2.Text - lvElement1.Text))
Else
Return Math.Sign(CLng(lvElement2.SubItems(iColumn).Text _
- lvElement1.SubItems(iColumn).Text))
End If
End If
Else 'Its a date
If bSortDirection = True Then
If iColumn = 0 Then
Return Date.Compare(Date.Parse(lvElement1.Text), _
Date.Parse(lvElement2.Text))
Else
Return Date.Compare(Date.Parse(lvElement1.SubItems(iColumn).Text), _
Date.Parse(lvElement2.SubItems(iColumn).Text))
End If
Else
If iColumn = 0 Then
Return Date.Compare(Date.Parse(lvElement2.Text), _
Date.Parse(lvElement1.Text))
Else
Return Date.Compare(Date.Parse(lvElement2.SubItems(iColumn).Text), _
Date.Parse(lvElement1.SubItems(iColumn).Text))
End If
End If
End If
End Function
End Class
|
|
|
|
|
thanks man
i did that, but i don't know why it didn't work
Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick
Dim a As New Eye_Salary.CompareListViewItems(e.Column.ToString, Me.ListView1)
End Sub
|
|
|
|
|
man i read the class
the fuction compare wasn't use
i didn't find a call for it
it should contain a loop on the items i think and make comparaison then a sorting
|
|
|
|
|
Just do this:
Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick
ListView1.ListViewItemSorter = New CompareListViewItems(e.Column, ListView1)
End Sub
My mistake
Sorry
|
|
|
|
|
try this one. it is much simplier
Private Sub LV_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
With LV
.SortKey = ColumnHeader.Index - 1
.SortOrder = lvwAscending
.Sorted = True
End With
End Sub
geboy
|
|
|
|
|
Hello,
making progress in trying to get atlas working...But not quite there yet...
To populate the dropdownlists from a database:
Public Function populateProjectDDL()
Dim knownCategoryValues As String
Dim category As String
(...)
(Filled my dataset called ds1.)
For Each datarowitem As DataRow In ds1.Tables(0).Rows
?!?!?!?!
Next
return ?!?!?!
end function
What do I return, how do i fill the whatever i return?
(http://atlas.asp.net/atlastoolkit/Walkthrough/CCDWithDB.aspx[^]
was trying to follow that example but they lost me in the c++)
Please help me? (asp.net forum mods won't let my posts appear)
|
|
|
|
|
Made progress...:
<webmethod()> _
Public Function populateProjectDDL(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
'Dim knownCategoryValues As String
'Dim category As String
'Which projects to show:
If Session("admin") = 1 Then
ds1 = dbComponent1.selectOneCondition("Project", "active", 1)
'info1.InnerText = "As admin, you see inactive projects, wells, sections and Drilling units as well."
Else
Dim querystr = "SELECT DISTINCT P.project_id, P.project_name FROM Project as P, UserRole as UR WHERE "
querystr = querystr + "UR.user_id = " & Session("active_user") & " AND "
querystr = querystr + "UR.project_id = P.project_id AND "
querystr = querystr + "P.active = 1"
ds1 = dbComponent1.query(querystr)
End If
Dim objTable As System.Data.DataTable
objTable = ds1.Tables(0)
If ds1.Tables(0).Rows.Count > 0 Then 'user cannot set defaults
With objTable
Dim intRow As Integer
Dim values As List(Of CascadingDropDownNameValue) = New List(Of CascadingDropDownNameValue)
For intRow = 0 To .Rows.Count - 1
values.Add(New CascadingDropDownNameValue(.Rows(intRow).Item("project_name").ToString, .Rows(intRow).Item("project_id")))
Next
Return values.ToArray
End With
Return New CascadingDropDownNameValue() {}
'Return knownCategoryValues
'Return category
Else
Return Nothing
End If
ds1.Clear()
End Function
Now [method error 500] in the project drop down...
|
|
|
|
|
Solved:
Solution:
include the populate of first drop down in aspx page, don't specify a servicepath for the first one, like this:
<WebMethod()> _
Public Function populateProjectDDLPageMethod(ByVal knownCategoryValues As String, ByVal category As String) As AtlasControlToolkit.CascadingDropDownNameValue()
(...)
|
|
|
|
|
My Task Is: Converting Raw Excel data to Sql Server Database.
Now i am taking my excel sheet data into Dataset, my major problem is my excel column has mixed data like, in column 1: Test, column2: 22/8/2006, Column 3: 226689.25, The total column i want to put into same column in the sqlserver, my dataset reads the data from excel sheet, it sets the datatype what first column has, that is String type, but the remaining data in the same column (ie) dates, rupees are considering as '0'(Zeros),
What is solution for this. Please help me
Regards
Murthy
|
|
|
|
|
i want to develop a telecom software in which the raw date of the call records(like trunk no,extn no,dialing no,call duration etc..)are to be extracted from the PBX by an interfacing data cable. the raw data can be recovered from the hyper termina by using a system defined function in vb.net
so i want to know about the system defined function & its usr for this purpose.
how to set this program as start up program so that when mu pc starts the program will automatically run
any queries/helps in this regard will be warmly solicited
i m pradip kishore from india,working in vb.net & asp.net
|
|
|
|