I have an application built in VB.NET. Everything is working great, here are the imports I'm using....
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Data.Odbc
Imports System.Windows.Forms.Control
Imports System.Windows.Forms.DataGridView
Imports System.Runtime.InteropServices.Marshal
Imports System.IO
I'm trying to do something with excel and added the following import which causes me some issues.....
Imports Microsoft.Office.Interop.Excel
In Public Class I have this...
Private DtTable as DataTable
The errors are:
DataTable is ambiguous, imported from the namespaces or types
'Microsoft.Office.Interop.Excel, System.Data'.
also, I have a function where I use this as a paramter...
ByRef c As Windows.Forms.ComboBox
I get the following error...
Type Windows.Forms.Combobox is not defined.
You'll need to declare explicity your DataTable like this:
Private DtTable as Data.DataTable
The same for the second error. Declare it like this:
ByRef c As System.Windows.Forms.ComboBox
That is because the name DataTable is in multiple namespaces. Do it this way instead.
Imports Microsoft.Office.Interop
Private xlTable as Excel.DataTable
or, if you want the standard DataTable
Private dtTable as DataTable
And you missed the "System" part in the combox scope. But again, you are better doing it this way.
Imports System.Windows.Forms
ByRef c As ComboBox
Related
I am making a program in VB.Net which requires the imports of four import thingamajiggys. However, Imports System.Security.Cryptography will not work alongside each other imports.
I've tried arranging the order they work in. Imports System.Security.Cryptography will not work at all with Systems.Net, but it will work alongside Imports System.Text and Imports System.IO
Imports System.Security.Cryptography
Imports System.IO
Imports System.Net
Imports System.Text
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Function SHA1(ByVal Content As String) As String
Dim Molecule As New Security.Cryptography.SHA1CryptoServiceProvider
Dim bytestring() As Byte = System.Text.Encoding.ASCII.GetBytes(Content)
bytestring = Molecule.ComputeHash(bytestring)
Dim finalstring As String = Nothing
For Each bt As Byte In bytestring
finalstring &= bt.ToString("x2")
Next
Return finalstring
End Function
A red wiggled line (like the spelling mistake in Word) appears under Security.Cryptography.SHA1CryptoServiceProvider but only when Systems.Net has been imported. Why does this happen?
You are getting the red wiggly line because System.Net also has a 'Security' namespace and it's trying to find Cryptography.SHA1CryptoServiceProvider in there.
To fix it either type
Dim Molecule As New System.Security.Cryptography.SHA1CryptoServiceProvider
or
Dim Molecule As New SHA1CryptoServiceProvider
You can use aliases.
Imports CryptoSecurity = System.Security
Imports MyNet = System.Net
Then in code
Dim Molecule As New CryptoSecurity.Cryptography.SHA1CryptoServiceProvider
You can use any names that make sense to you for the alias.
My class gives me an error:
Error 4 Expression of type 'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.
I searched similar questions and found out it may be problem with imports/references. However, I think I imported everything I need and it still gives me the error.
The class and project references are below:
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Data
Imports System
Imports System.Xml
Imports System.Xml.Linq
Public Class Form1
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Dim Result As Integer
Dim mxldDataParams As System.Xml.Linq.XDocument = XDocument.Load("mypath\myxml.xml")
Private Function GetProcedureName(ByVal Name As String) As String
Dim Result As String = String.Empty
'this line gives the error
Dim Elems As System.Collections.Generic.IEnumerable(Of XElement) = From Elem As XElement In mxldDataParams.Root.Elements Where Elem.Name.LocalName = "data" And Elem.#name = Name
For Each Elem As XElement In Elems
Result = Elem...<target>...<remote>...<source>.#name
Exit For
Next
Return Result
End Function
End Class
You don't have an import for System.Linq, which means the compiler can't find LINQ to Objects, which is the LINQ implementation you're trying to use.
Just add this to your imports:
Imports System.Linq
LINQ to XML isn't really a LINQ provider - it's just an XML API which also works well with LINQ to Objects.
How to use createDocumentFromUrl in vb.net. I got information like we should use IPersistStreamInit interface if we want to work on this. So i want an example showing this.
I would not recomend going alone into that interface, But I am guessing that you are doing this in a dll/cmd line so you can't use the winform solution so you can use htmlAgility pack and you can download it as a nuget HtmlAgilityPack
But If you have to go the interop way you can check out this question Getting the HTML source from a WPF-WebBrowser-Control using IPersistStreamInit
And the only thing you need to add for vb is this
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose()
GC.SuppressFinalize(Me)
End Sub
But using the agility pack you can do it like this:
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Net
Imports System.IO
Imports HtmlAgilityPack
Class Program
Private Shared Sub Main(args As String())
Dim wc As New WebClient()
Dim doc As New HtmlDocument()
doc.Load(wc.OpenRead("http://google.com"))
End Sub
End Class
I got 11 errors in my VB program. All the errors look similar: X is ambiguous in the namespace Y
Error line: Imports System.Net.Sockets
Imports System.Text
Module Module1
Sub Main()
Dim serverSocket As New TcpListener(System.Net.IPAddress.Parse("192.168.1.100"), 8888)
How might I resolve this?
I suspect that you've added two different references for assemblies that define System.Net.Sockets. (Probably System.dll for .NET 2.0 and .NET 4.0, but that's neither here nor there.)
I say this because there's nothing wrong with your code:
Imports System.Net.Sockets
Imports System.Text
Module Module1
Sub Main()
Dim serverSocket As New TcpListener(System.Net.IPAddress.Parse("192.168.1.100"), 8888)
End Sub
End Module
result: success time: 0.16s memory: 25064 kB returned value: 0
This is with SQL 2005.
I have a script component inside a Data Flow Task. I would like to read from the input columns and write the data to a global user variable.
I've set my input columns and added my global user variable as a ReadWriteVariable to the script component properties.
Here is my code, I'm just trying to alter the value of the global user variable here, but its not working. When I write out the value of the variable in another task it still has its default value:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Public Class ScriptMain
Inherits UserComponent
Dim updateSQL As String
Public Sub Main()
Dim vars As IDTSVariables90
VariableDispenser.LockOneForWrite("SQL_ATTR_Update", vars)
vars("SQL_ATTR_Update").Value = "Test"
vars.Unlock()
End Sub
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
'updateSQL = Row.ITMID + Row.PRCCAT
End Sub
End Class
I have also tried with no luck:
Me.ReadWriteVariables("SQL_ATTR_Update").Value = "Test"
I figured it out.
From MS:
In Script component code, you use
typed accessor properties to access
certain package features such as
variables and connection managers.
The PreExecute method can access only
read-only variables. The PostExecute
method can access both read-only and
read/write variables.
For more information about these
methods, see Coding and Debugging the
Script Component.
http://msdn.microsoft.com/en-us/library/ms136031.aspx
It looks like Dts is only available in Script Task.
Here is what the code looks like:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Public Class ScriptMain
Inherits UserComponent
Dim updateSQL As String
Public Overrides Sub PostExecute()
Me.ReadWriteVariables("SQL_ATTR_Update").Value = "Test"
End Sub
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
'updateSQL = Row.ITMID + Row.PRCCAT
End Sub
End Class
Here is how you could do it:
http://microsoft-ssis.blogspot.com/2011/01/how-to-use-variables-in-script.html
Use
Dts.Variables("SQL_ATTR_Update").Value = "Test"
And SQL_ATTR_Update needs to be a global variable and listed in your ReadWriteVariables for that script task.