|
now how can I access it?
BiG RaLpH
|
|
|
|
|
there a few possible ways:
1) declare the control you want to access global (dim w as webbrowser)
when you create it you first need to initialize it ( w = new webbrowser)
this way you can access the control from anywhere (always check first if it has been initialized ( if w isnot nothing then 'do you're code))
2) when you create the control give it a unique name (w.name = "unique")
then when you want to access it you can just run true the controls on you tabcontrol (normally all tabpages) and for each tabpage run true his controls and compare name
(if control.name.tolower.equals("unique") then ' do you're code)
this is a bit more work and I think it's better to use the first option (for performance) but it should also work
hope this helps
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|
|
Hello all!
I'm having a complicated problem here, here goes;
At my development workspace, im running on Vista, VB .net 2005 and the DB on SQL Express 2005. Now i would normally insert a date value as such;
INSERT INTO Table(DateColumn) VALUES ('" & "yyyymmdd" & '")
The date that is in yyyymmdd format without slashes in between, and its in a string format.
As far as it is, it works well.
But now my problem is, when I tried my program on another system (Windows XP), I couldnt be able to insert a date in such a way, an error states that 'unable to convert to smalldatetime ..etc'
ive' tried changing my method to as such,
INSERT INTO Table(DateColumn) VALUES (" & dateValue.Date & ")
it works, to most extent, but the weird part is, some areas in my program dint turn out to work as well as it's expected. The values are inserted into the DB but its showing "1/1/1900" ! As mentioned, using the same identical method on other areas dint have a problem.
What should I do? Why couldnt I in the first place, replicate the success I had over with my Vista workspace onto the other PC. (2 in fact, both running on XP).
Should I define how the database should accept date values? or?
Thanks in advance! Do need some advices here..
Regards,
Jensen
|
|
|
|
|
This is the problem with using string concantenation to build SQL query statements. Convert this to a parameterized query and you shouldn't have a problem with it at all.
Read SQL Injection Attacks[^] and it'll explain what a parameterized query is.
|
|
|
|
|
I know about creating parameterized queries but ive used it only at certains areas in my program.
I dint know its significant until now! It's really odd and I wouldn't have known if I dint come in here and asked!
Thanks once again!
|
|
|
|
|
Have you tried something like this:
INSERT INTO Table(DateColumn) VALUES (cast '" & "yyyymmdd" & '" as date)
You always pass failure on the way to success.
|
|
|
|
|
yes, but it works on some statements and wouldnt work the other half, its oddly strange but ive used the method specified by Dave ( see above ). It works, guess from now, ill just build all my statements using parameters.
but thanks for the suggestion!
|
|
|
|
|
maybe this is not really a problem with your SQL statement:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DateTime
Console.WriteLine("New Date {0}, Year={1}, Month={2}, Day={3}", dt.ToString("yyyy/MM/dd"), dt.Year.ToString(), dt.Month.ToString(), dt.Day.ToString())
End Sub
what does your db do with "empty" dates?
|
|
|
|
|
I’m working on creating a Visio 2003 organization chart over .net, I have been code it by using VB.Net 2005. What I’m trying to do is to retrieve the organization chart hierarchical from the database and store it as an html web page. I have been used the organization chart wizard for creating the chart shapes and I used VisSaveAsWeb object to save the chart as a web page. My problem is that the org chart shapes doesn’t formatted correctly after resizing the shapes to fit with it text. Is there any one know how could I control the shape position to relocate it into it right place
and this is my peace of code
Code Block
'On Error GoTo OrgDoItErrHandler<br />
<br />
Dim objVisio As Visio.Application<br />
<br />
Dim objAddOn As Visio.Addon<br />
<br />
Dim vsoSaveAsWeb As VisSaveAsWeb<br />
<br />
Dim vsoWebSettings As VisWebPageSettings<br />
<br />
Dim strCommand As String<br />
<br />
Dim i As Integer<br />
<br />
Dim pagObj As Visio.Page<br />
<br />
Dim shpObj As Visio.Shape<br />
<br />
Dim celObjHeight As Visio.Cell<br />
<br />
Dim celObjWidth As Visio.Cell<br />
<br />
<br />
<br />
strCommand = "/DATASOURCE=SN,TABLE=" _<br />
<br />
& "~" & ",DBQUALIFIER=~" _<br />
<br />
& " /NAME-FIELD=~" _<br />
<br />
& " /UNIQUEID-FIELD=~" _<br />
<br />
& " /MANAGER-FIELD=~" _<br />
<br />
& " /DISPLAY-FIELDS=~" _<br />
<br />
& " /CUSTOM-PROPERTY-FIELDS=~" _<br />
<br />
& " /SHAPE-FIELD=~"<br />
<br />
<br />
<br />
objVisio = New Visio.InvisibleApp<br />
<br />
<br />
<br />
objAddOn = objVisio.Addons.ItemU("OrgCWiz")<br />
<br />
<br />
<br />
'Run the add-on (errors are handled by the add-on)<br />
<br />
On Error Resume Next<br />
<br />
<br />
<br />
'Break up the string<br />
<br />
Dim strCommandPart As String<br />
<br />
Dim strCommandLeft As String<br />
<br />
strCommandLeft = strCommand<br />
<br />
objAddOn.Run("/S-INIT")<br />
<br />
While (Len(strCommandLeft) > 0)<br />
<br />
strCommandPart = Microsoft.VisualBasic.Left(strCommandLeft, MAX_ARGSTRING_LENGTH)<br />
<br />
strCommandLeft = Mid(strCommandLeft, Len(strCommandPart) + 1)<br />
<br />
objAddOn.Run("/S-ARGSTR " + strCommandPart)<br />
<br />
End While<br />
<br />
objAddOn.Run("/S-RUN " + strCommandLeft)<br />
<br />
<br />
<br />
' Get a VisSaveAsWeb object that<br />
<br />
' represents a new Web page project.<br />
<br />
vsoSaveAsWeb = objVisio.Application.SaveAsWebObject<br />
<br />
' Get a VisWebPageSettings object.<br />
<br />
vsoWebSettings = vsoSaveAsWeb.WebPageSettings<br />
<br />
' Configure preferences.<br />
<br />
With vsoWebSettings<br />
<br />
.StartPage = 1<br />
<br />
.EndPage = 2<br />
<br />
.QuietMode = True<br />
<br />
.TargetPath = "D:\Balaji\Test.htm"<br />
<br />
.SilentMode = True<br />
<br />
End With<br />
<br />
<br />
<br />
pagObj = objVisio.ActivePage<br />
<br />
<br />
<br />
' I’m trying here to resize the shaps to fet with the texts that inside it<br />
<br />
<br />
<br />
For i = 0 To pagObj.Shapes.Count<br />
<br />
If pagObj.Shapes.Item(i).Name.Contains("Executive") Or pagObj.Shapes.Item(i).Name.Contains("Manager") Or pagObj.Shapes.Item(i).Name.Contains("Position") Then<br />
<br />
pagObj.Shapes.Item(i).CellsSRC(1, 1, 0).FormulaForceU = "4.25 in"<br />
<br />
pagObj.Shapes.Item(i).CellsSRC(1, 1, 1).FormulaForceU = "9.15625 in"<br />
<br />
pagObj.Shapes.Item(i).CellsSRC(1, 1, 3).FormulaForceU = "1.6875 in"<br />
<br />
End If<br />
<br />
Next i<br />
<br />
<br />
<br />
' Create the pages. Because no particular document<br />
<br />
' is specified, the active drawing is saved.<br />
<br />
<br />
<br />
vsoSaveAsWeb.CreatePages()<br />
<br />
<br />
<br />
objVisio.ActiveDocument.Saved = True<br />
<br />
objVisio.ActiveDocument.Close()<br />
<br />
objAddOn = Nothing<br />
<br />
objVisio.Quit()<br />
<br />
objVisio = Nothing<br />
<br />
<br />
<br />
Exit Sub<br />
<br />
<br />
<br />
OrgDoItErrHandler:
i try to learn programming what ever i had i feal that i did'nt get anything
|
|
|
|
|
I have a database (sql server 2000) is suspect, please help me, thanks.
|
|
|
|
|
Phan Van Thao wrote: I have a database (sql server 2000)
Congratuations...
Phan Van Thao wrote: database (sql server 2000) is suspect,
And that means what exactly?? Suspects of what??
Phan Van Thao wrote: please help me, thanks.
Can't. You haven't supplied any information about what the problem is.
|
|
|
|
|
This is more of a SQL question.
I have come across this situation myself and my suggestion is to try and detach and then re-attach the database in Enterprise Manager - this sometimes fixes the issue.
I don't want to recommend deletion of log files etc as I don't want to be held responsible for loss of data.
Googling the issue bought this up:
A database can be marked for many reasons. Generally it falls into the following conditions :
* A database or log file is missing.
* In SQL 6.5, a device may not be present or in 7.0/2000 a file may not exist.
* SQL Server may not have been able to restore the database in ample time.
* The database could be corrupt.
* The database is being help by the operating system. This could be a 3rd party backup software or defrag software. I've had even a virus scanning software cause this once.
* SQL Server does not have enough space to recover the database on startup.
You always pass failure on the way to success.
|
|
|
|
|
what r the properties to change the progressbar forecolor and backcolor
|
|
|
|
|
There are no properties for this. If you want to change the appearance of the ProgressBar, you're going to have to create your own version of it. Create a new class that inherits from ProgessBar and add the properties and code for BackColor, ForeColor, and all the drawing code to custom draw the control.
|
|
|
|
|
Hola,
I am working on a tool that from one side connects to a simulation model using ActiveX and to the other side to a control system via Sockets.
The only thing the tool should do is making connections to both parties (simulation model and real controls) and send message through between the two components.
For the socket side of the tool I made this code with a lot of copy pasting from websites (see below). But it doesnt work... A connection is made, but receiving and sending is not working. I dont understand what to do with the receive function (which parameters). I only want to receive a string (size 100) through the connection. Sending seems to work because the real controls get stuck when I call the SendMessage sub.
Another question is how I can automatically react on a incoming message instead of checking this every 0.1 sec (I call the sub every 0.1 sec). Is there an event defined that wakes up when incoming data arrives?
Please help.
Imports System<br />
Imports System.Text<br />
Imports System.IO<br />
Imports System.Net<br />
Imports System.Net.Sockets<br />
Imports Microsoft.VisualBasic<br />
<br />
Public Class MySockets<br />
<br />
Dim Listener As Socket<br />
Dim Sender As Socket<br />
Public Function ConnectSocket(ByVal server As String, ByVal port As Integer) As Socket<br />
<br />
<br />
Listener = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)<br />
<br />
' bind the listening socket to the port<br />
Dim hostIP As IPAddress = Dns.Resolve(IPAddress.Any.ToString()).AddressList(0)<br />
Dim ep As New IPEndPoint(hostIP, port)<br />
Listener.Bind(ep)<br />
<br />
' start listening<br />
Listener.Listen(1)<br />
<br />
Sender = Listener.Accept()<br />
<br />
Return Sender<br />
End Function<br />
<br />
Public Sub SendMessage()<br />
<br />
Dim Data As String<br />
Data = "HolaHola"<br />
<br />
Dim msg As Byte() = System.Text.Encoding.ASCII.GetBytes(Data)<br />
<br />
Debug.Print(Sender.Connected)<br />
Sender.Send(msg)<br />
End Sub<br />
<br />
Public Sub ReceiveMessage()<br />
Dim vbBytes As Int32<br />
Dim buffer As Byte()<br />
Dim vsString As String<br />
vbBytes = Listener.Receive(buffer)<br />
<br />
vsString = Encoding.ASCII.GetString(buffer, 0, vbBytes)<br />
End Sub<br />
End Class
|
|
|
|
|
Nasbcn wrote: I made this code with a lot of copy pasting from websites (see below). But it doesnt work...
The problem with copy'n'paste coding is that you have little to no understanding of the code, how it works, or why. This alone makes it impossible for you to support the code. When something breaks, you're utterly lost.
Using a Timer to call anyof this code is a really bad idea. You've got no control over the flow of the code and the data it's carrying.
Here's[^] a good example of how it should be done. You should study the Server side of this code.
|
|
|
|
|
Hi All
i have a Function in my Component(DAL), the Function Accept an intiger value and return a dataset.
<br />
<br />
Public Function Search_lis(ByVal lis_key As Integer) As Dssearchlis<br />
<br />
dasearchlis.SelectCommand.Parameters.Add(lis_key)<br />
dasearchlis.Fill(Dssearchlis)<br />
If Dssearchlis.Tables("Property_Mass").Rows.Count = 0 Then<br />
MsgBox("Township not Found")<br />
Else<br />
Dssearchlis.Clear()<br />
dasearchlis.Fill(Dssearchlis)<br />
<br />
End If<br />
Return Dssearchlis<br />
End Function<br />
Am Calling this Function in my Form. like this
Dim objsearch As New PropDAL.Properties
Dim dsdata As New PropDAL.dssearchlis
Dim txtseachlis As Integer
txtseachlis = Val(txtlisSearch.Text)
Dim strErrorMsg As String
Dim strerror As System.Data.SqlClient.SqlError
Try
dsdata = objsearch.Search_lis(txtseachlis)
dgr.DataMember = "Property_Mass"
dgr.DataSource = dsdata
Catch ExSQL As System.Data.SqlClient.SqlException
''''All this will trap all data Problems and Network if available
For Each strerror In ExSQL.Errors
Next
Select Case strerror.Number
Case 17
strErrorMsg = "Missing server"
Case 4060
strErrorMsg = "Missing database"
Case 18456
strErrorMsg = "Missing user name or password"
Case Else
strErrorMsg = strerror.Message
End Select
MessageBox.Show(strErrorMsg, "SQL Server Error: " & strerror.Number, MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch ExcpInvOp As System.InvalidOperationException
MessageBox.Show("Close the connection first!", "Invalid Operation", MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch Excp As System.Exception ' generic exception handler
MessageBox.Show(Excp.Message, "Unexpected Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
What is Wrong , and what should i put in mind when dealing with parameters, i know i should have used a storedProcedure, but for now i need to use this.
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Should this not be in the coding horrors forum?
|
|
|
|
|
This code has so many problems, I don't know where to start...
First, you've made a VB.NET 101 mistake. You're returning an object of type Dssearchlis , which is also the name of an apparently "global" object. It get the feeling that you're returning the exact same object that is already visible outside the function, making retuning the object pointless.
|
|
|
|
|
Hi I want to disable/ enable my save all button if changes exist in the datagridview. Where would I need to put the code and what does that code typically look like? Thanks in advance. Im aware that I have to set the button to "enabled = false" but where? and how do I check for changes?
Mr Oizo
|
|
|
|
|
hi
Try this
If DataSet111.HasChanges = True Then
btnSave.Enabled = true
else
btnsave.Enabled = False
end if
hope it helps
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Handle the DataGridView's CurrentCellDirtyStateChanged event. Then the code would probably look something like:
If DataGridView1.IsCurrentCellDirty Then
' Enable save changes button.
End If
Do NOT put in code to disable the button! Once a cell is dirty, consider the entire dataset dirty, even if this cell is changed back to it's original value!
|
|
|
|
|
Ok thanks for the help. you say I shouldn't disable the save button at all but I seem to get data cncurrency errors in my code when I save the same values twice. What happens is that an autonumber is generated for each song in my song library whena new song is added and when i call savechanges it gives me a concurrency error if i hit save twice in a row. so I just wanna disable that button when they have already pressed save and if they edit further then re-enable the button. Any ideas where to put the code?
Mr Oizo
|
|
|
|
|
Mr Oizo wrote: but I seem to get data cncurrency errors in my code when I save the same values twice.
OK. Obviously, you can reset the save button AFTER the changes are saved. Come on, think!!
|
|
|
|
|
I think i have a big problem with my program.I have sat for 3 weeks with this data concurrency error and I can't fix it. it is happening in a project i'm writing for my thesis and at the moment i'm gonna fail just because this is stopping me from continuing with the rest of my project. the problem is that I can add data to a dataset but as soon as I try to edit the newly added data and save a data concurrency error appears(o records updated out of the expected 1 record(or similar to that)). I have read tons of articles and still can't find the problem. It's a single user environment, my dataset tables and database tables have the same field types and everything. the update statement looks fine. the only thing that i can assume is wrong is something to do with the fact that i have a datagridview and several textboxes bound to the underlying dataset and when I call "saveChanges" it tries to save the values from both the textbox for the column and the datagridview for the column. the only code used by my textboxes and datagrid is databinding code eg:
modbdaSongNewest2.ClearBeforeFill = True<br />
modbdaSongNewest2.Fill(DsLibraryNewest2.Song)<br />
<br />
' bindingSong is a bindingsource object<br />
<br />
bindingSong.DataSource = DsLibraryNewest2<br />
bindingSong.DataMember = "Song"<br />
<br />
<br />
dgSongProperties.DataSource = bindingSong
txtArtist.DataBindings.Add("Text",bindingSong, "Artist",_<br />
True, DataSourceUpdateMode.OnPropertyChanged)
When adding new songs to the library I use the Openfiledialog and run a for loop for each file that was selected and add rows using this code which is pretty standard:
Dim FileInfo As System.IO.FileInfo ' This variable will hold the selected file info<br />
Dim drCurrentSong As dsLibraryNewest2.SongRow<br />
<br />
If Not (dlgOpenFile Is Nothing) Then<br />
<br />
<br />
For i = 0 To dlgOpenFile.FileNames.GetUpperBound(0)<br />
FileInfo = My.Computer.FileSystem.GetFileInfo(dlgOpenFile.FileNames(i))<br />
' This will retrieve the foldername for the file<br />
Dim folderPath As String = FileInfo.DirectoryName<br />
' MsgBox(folderPath)<br />
' This will retrieve file name for the file<br />
Dim fileName As String = FileInfo.Name<br />
'MsgBox(fileName)<br />
<br />
' This will retrieve the full path of the file <br />
Dim absolutePath As String = FileInfo.FullName<br />
' MsgBox(absolutePath)<br />
<br />
Try<br />
drCurrentSong = DsLibraryNewest2.Song.NewSongRow<br />
<br />
With drCurrentSong<br />
<br />
.FileName = fileName<br />
.FolderPath = folderPath<br />
.AbsolutePath = absolutePath<br />
<br />
End With<br />
DsLibraryNewest2.Song.AddSongRow(drCurrentSong)<br />
' Call SaveChanges()<br />
<br />
Catch ex As System.ArgumentException<br />
DsLibraryNewest2.Song(mintCurrent).CancelEdit()<br />
<br />
Catch ex As System.Data.ConstraintException<br />
MessageBox.Show( _<br />
ex.Message, _<br />
"Error", MessageBoxButtons.OK)<br />
DsLibraryNewest2.Song(mintCurrent).CancelEdit()<br />
<br />
End Try<br />
mintCurrent += 1<br />
Next<br />
<br />
End If<br />
<br />
<br />
End Sub
anyway that code all works fine. the problem is editing the data not adding it. So the only code I have for editing is the binding bit in the from load event and this bit:
Private Sub dgSongProperties_RowLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgSongProperties.RowLeave<br />
<br />
' this line below doesn't really do anything <br />
<br />
dgSongProperties.Update()<br />
<br />
End Sub<br />
<br />
<br />
<br />
<br />
<br />
<br />
Private Sub BindingSource1_BindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.BindingCompleteEventArgs) Handles bindingSong.BindingComplete<br />
<br />
'the following code Checks if the data source has been updated, and that no error has occured.<br />
If e.BindingCompleteContext = BindingCompleteContext.DataSourceUpdate _<br />
AndAlso e.Exception Is Nothing Then<br />
<br />
' If not, end the current edit.<br />
e.Binding.BindingManagerBase.EndCurrentEdit()<br />
<br />
End If<br />
<br />
<br />
End Sub
i know you are really busy and I have probably just left something out or forgot to call something. My other forms all work correctly and update their data but this one with the datagridview that has textboxes bounded to the datatable has a problem? if you can help me then please do... time is running out for me. thank you
Mr Oizo
|
|
|
|
|