Over 6 years ago I did visual basic programming. I used VB6 for an editor. I did it for a semester in college, and I didnt make a good grade. Since then I have been doing other things in life. However I was asked at work to create a web application. I am creating my application in vb.net 2003. I began desigining the interface of the web form. I have 5 forms, all of them need to connect to a database which I already have prepared. I created the database in MS Access. If I can get one of the forms to look at the database, I think I can get the rest of them to do it. I have tried using beginner tutorials online and I am not finding anything thats helpful. The closest tutorial I have found that could atleast give me an idea of what to do, the code doesnt work, I did everything to the 'T'. http://www.startvbdotnet.com/ado/msaccess.aspx
Is there anyone out there that can help me?
What you are looking for to access Microsoft Accesss Databases (MDB) is the Microsoft JET Client. If you are using a Visual Studio here is the VB for simple access. You can query the database file with SQL.
Outside class
Imports System.Data.OleDb
Imports System.Data
Inside class, to access the database
Dim cn As OleDbConnection
Dim db As OleDbDataAdapter
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\folder\file.mdb;")
cn.Open()
db = New OleDbDataAdapter("select * from Table1", cn)
Dim ds As New DataSet()
db.Fill(ds)
For Each row As DataRow In ds.Tables(0).Rows
me.txtRow1.text = row("Row1")
me.txtRow2.text = row("Row2")
me.txtRow3.text = row("Row3")
Next
cn.Close()
cn.Dispose()
cn = Nothing
For more information go to, http://en.wikipedia.org/wiki/Microsoft_Jet_Database_Engine . Hope it helps!
A 'low barrier to entry' of using an Access DB with VB.Net would be to import the ADODB COM library. Since you've done VB6 before, you should be familiar with the "classic" ADO syntax.
I'm using it right now with a small VB.Net 2008 app and it works perfectly fine. No need to deal with data connections, adapters, fill methods, data sets, or data tables.
Related
I have an ASP.NET Webforms Application where the user can create reports with server-side office Automation. It basically works with FormFields that are being filled out and in the end the user gets a download with the Office document. The Application is quite old and I did not design this software. I'm also aware of the side effects of office server Automation and this article:
https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office
It just works for almost 15 years with several different Office Versions, the newest one is Office 2016 but now I have to know if it still would work with Office 365. It looks like a hybrid solution, Software as a Service but still requires installation on the machine somehow.
It's a little bit hacky to set up like:
IIS Application User needs to take ownership of the following folder:
C:\Programme(x86)\Microsoft Office
C:\Programme\Microsoft Office
C:\Windows\System32\config\systemprofile\AppData
C:\Windows\System32\config\systemprofile\Desktop (sometimes missing
so it needs to be created)
C:\Windows\SysWOW64\config\systemprofile\AppData
C:\Windows\SysWOW64\config\systemprofile\Desktop (sometimes missing
so it needs to be created)
C:\Programme(x86)\Microsoft.Net\
C:\Program Files (x86)\Microsoft ASP.NET\
And in addition, some DCOM Configuration for Word and Excel needed. The IIS Application User needs permission to start the office application etc.
I'm not sure if all the requiered dependency are still there with office 365.
Here is a code snippet:
Function CreateDoc(ByVal docpath As String, ByVal docname As String, ByVal Document As String) As String
Dim ff_name As String = ""
Dim strFileName As String = Nothing
Dim strExtension As String = Nothing
Dim fileBytes As Byte() = Nothing
Try
Dim w = New Word.Application
w.Visible = m_obj.Project.OfficeDisplay
w.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
w.Documents.Open(docpath)
SetRanges(Document)
Dim i As Integer
For Each ff As Word.FormField In w.ActiveDocument.FormFields
.
.
.
The good news first. If it's work with Office 2016 it should work good with Office 365 too. The bad news now, with the monthly evolution the usage of office interop risk to create issue in the future (in months, or probably more in years), it's difficult without auditing all the solution to give you answer. The next step will be to see if your application could be transform in Web Add-in with offie.js or use Graph API. But unfortunately lot of stuff we do in interop are not possible with the modern solution...
Nothing has been changed so far with desktop editions of Microsoft Office. But I'd recommend using the Open XML SDK for generating documents on the server-side, see Welcome to the Open XML SDK 2.5 for Office for more information.
I am having a really wired issue where I have created a new ASP.Net 4.6 web application (Visual Studio 2015 Community Edition) and everything works fine.
The app will compile without any issues at all but as soon as I try to run the app on the development machine (Windows 10 Enterprise) I get the following error every time and I cannot figure out why?
BC30002: Type 'ConnectionOptions' is not defined.
The code I am using is as follows:
Dim Options As New ConnectionOptions()
Options.Username = HttpContext.Current.Application("WMIUser")
Options.Password = HttpContext.Current.Application("WMIPsssword")
Dim scope As New ManagementScope("\\" & server_name & "\root\cimv2", Options)
scope.Connect()
Dim objectQuery As New ObjectQuery("SELECT FreeSpace FROM Win32_LogicalDisk where DeviceID=""" + deviceId + ":""")
Dim objectSearcher As New ManagementObjectSearcher(scope, objectQuery)
Dim objectCollection As ManagementObjectCollection = objectSearcher.[Get]()
For Each m As ManagementObject In objectCollection
Dim FreeSpace As Double = Convert.ToDouble(m("FreeSpace"))
Next
I have a reference to the System.Management DLL in the references for the application and I have an Imports declaration for it also.
Has anyone come across this before? My searching all leads back to the DLL not being referenced in the application but I have added and removed and re-added without any change.
Please help this is driving me nuts :-(
OK so this is a funny one, posting up just in case someone else comes across the issue.
The way I resolved this problem on the development machine was under References for the project, you have the option to copy local, set this to true and rebuilt the application, ran it and hey presto it all worked.
I can only assume that this could be a permissions thing but this works for the moment anyway.
Hope this helps someone in the future.
I'm working with MSSQL Server 2008 and made a database in it.
Now i made a ASP.Net (MVC 4) project and connected it to the database. I let visual studio generate the Entity Data Model and everything is working fine so far.
Now i have a table for a many to many relation with ofcourse a PK, and two FK. When i manualy insert a row to the database with Microsoft SQL Server Management Studio and i refresh my web page this new row doesn't show up.
I'm 100% sure there is nothing wrong with the C# code (ASP.Net) but after X minutes the row show up :s.
Do i need to update the datasource somewhere or what do i do wrong? (it's my first ASP.Net project :))
Thnx!
Code edit:
private dbEntities db = new dbEntities();
This dbEntities is generated by visual studio from the SQL Server and contains models for all tables.
It sounds like your data context is stale (it's retrieving the data from memory and not going to the DB).
See this question or this one for a possible solution.
Edit: Looking at your sample code, I'm going to guess that this has been declared as a page (or class) member. You should wrap this in a using statement so the object context can be disposed:
e.g.
using (var db = new dbEntities())
{
//perform work
}
I'm trying to figure out how to use the Microsoft Online Services Migration Toolkit PowerShell Commands from within an ASP.NET website (using vb.NET).
I've started off using a guide on how to use PowerShell in ASP.NET - from here: http://devinfra-us.blogspot.com/2011/02/using-powershell-20-from-aspnet-part-1.html
I'm trying to work out how to implement the Online Services Migration Toolkit PowerShell cmdlets.
Here is a snippet from my code-behind:
Sub GetUsers()
Dim iss As InitialSessionState = InitialSessionState.CreateDefault()
iss.ImportPSModule(New String() {"MSOnline"})
Using myRunSpace As Runspace = RunspaceFactory.CreateRunspace(iss)
myRunSpace.Open()
' Execute the Get-CsTrustedApplication cmdlet.
Using powershell As System.Management.Automation.PowerShell = System.Management.Automation.PowerShell.Create()
powershell.Runspace = myRunSpace
Dim connect As New Command("Get-MSOnlineUser -Enabled")
Dim secureString As New System.Security.SecureString()
Dim myPassword As String = "ThePassword"
For Each c As Char In myPassword
secureString.AppendChar(c)
Next
connect.Parameters.Add("Credential", New PSCredential("admin#thedomain.apac.microsoftonline.com", secureString))
powershell.Commands.AddCommand(connect)
Dim results As Collection(Of PSObject) = Nothing
Dim errors As Collection(Of ErrorRecord) = Nothing
results = powershell.Invoke()
errors = powershell.Streams.[Error].ReadAll()
For Each obj As PSObject In results
Response.Write(obj.Properties("Identity").Value.ToString())
Next
End Using
End Using
End Sub
When I try to run the code via the page, I'm getting the following error
The term 'Get-MSOnlineUser -Enabled' is not recognized as the name of
a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path
is correct and try again.
So I'm guessing I haven't worked out how to import the Online Services Migration Toolkit PowerShell CmdLets. I'm also not exactly sure if the line:
iss.ImportPSModule(New String() {"MSOnline"})
Is exactly correct. Is there a way I can verify the Module name?
I'm also unsure of where and how to reference the .dll files. At the moment I have copied them to my bin folder but I can't add them as references, so how does the ImportPSModule statement know where to find them? Especially when the website is published to the final production server.
One other question, should I be using the x86 or x64 cmdlets? I'm developing on Win7 x64, but not sure if the website builds as x86 or x64? Do I need to find out what architecture the server is?
"Get-MSOnlineUser -Enabled" is not a command; "Get-MSOnlineUser" is. I'm a bit confused how you got it correct further down the script with connect.Parameters.Add("Credential", ...) but didn't do the same thing for -Enabled.
Use connect.AddArgument("Enabled") or connect.Parameters.Add("Enabled", true) and you should be good to go.
I'm trying to open a database (using vb) using database.open but there is no Intellisense for this. What do I need to do to open a database? All of the examples I can find show database.open("ConnectionString") but this option isn't available to me.
I'm with with a fresh ASP.NET Razor application (not MVC) and have a web.config reference to a suitable database.
Are you talking about complete ado.net basics? If you are, check this site out: using ado.net with VB.Net and C#
You actually want to create the object for the sql connection before you open the connection:
Dim sqlConn as new SqlConnection("ConnectionString")
sqlConn.Open()
Also, in your web project, you need to add the reference System.Data (this should add System.Data.SqlClient) and this will need to be imported using
Imports System.Data
Imports System.Data.SqlClient
at the top of the page before the class.
Hope this makes sense.