discovery-power 0 Junior Poster in Training

try

if instr(mainPath, "xx") > 0 then msgbox "mainPath containsxx"

This seems to throw the msgbox up even though xx is not in the file name.

I think I might have to re-thing the way I have written out the code altogether, I am not really comfortable with it, the way it's laid out doesn't seem to make much sence, it's all just willy nilly.

Back to the drowing board with this one

Thanks for the help.

John

discovery-power 0 Junior Poster in Training

What are you trying to compare to "xx", are you sure you don't mean

If mainPath.Substring(0, 2) = "xx" Then

Hi Chris,

This line of code checks to see if the file has "xx" in the file name, if it does then it is an encrypted file and it wants decrypting.

If it does not have "xx" then it will be encrypted.

The variable mainPath is a global one and is written

Dim mainpath As String

I have tried writing If mainPath.Substring(0, 2) = txtBoxFileLocation.Text = "xx" Then... but I still get the same exception.

This project is s close to being completed I can almost taste it, I just need to clear this issue. (I hope it's the last issue lol)

discovery-power 0 Junior Poster in Training

&lt and &gt is normally used in HTML to replace < and >but not in actual code. Replace those &lt and &gt with < and > in your code and it should work.

Hi Hericles,

Thanks for the reply, that has sorted that issue, I had no idea that &alt translated to <

I have attempted to run the software and I get a Null Exception on this line of the code

If mainPath.Substring(mainPath.Length - 2) = "xx" Then

I can't see why that would happen as all my controls are coded in??

I am going to create seperate buttons for the ecrypt and decrypt process and see if that helps.

discovery-power 0 Junior Poster in Training

Hi All,

I have written my-self a file encryption application, but I am getting the following error from on this peice of code

the eroor is : NAME 'it' is not declared

Please see my code below

Imports System.IO
Imports System.Text
Imports System.Security.Cryptography
Public Class Form1
    Inherits System.Windows.Forms.Form
    'creates an 8 bit long array to hold the key
    Public TheKey(7) As Byte
    'some random values into the vector
    Private Vector() As Byte = {&H12, &H44, &H16, &HEE, &H88, &H15, &HDD, &H41}

    'Encryption Procedure

    Sub Encrypt(ByVal inName As String, ByVal outName As String)
        Try
            Dim storage(4096) As Byte 'create buffer
            Dim totalBytesWritten As Long = 8 'keeps track of bytes written
            Dim packageSize As Integer 'specifies the number of bytes written at one time
            'declair the file streams
            Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read)
            Dim fout As New FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write)
            fout.SetLength(0)
            Dim totalFileLength As Long = fin.Length 'specefies the size of the source file
            'create the crypto object
            Dim des As New DESCryptoServiceProvider()
            Dim crStream As New CryptoStream(fout, des.CreateEncryptor(TheKey, Vector), CryptoStreamMode.Write)
            'flow the streams

            While totalBytesWritten &lt; totalFileLength
                packageSize = fin.Read(storage, 0, 4096)
                crStream.Write(storage, 0, packageSize)
                totalBytesWritten = Convert.ToInt32(totalBytesWritten + packageSize / des.BlockSize * des.BlockSize)
            End While
            crStream.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    'Decryption Procedure

    Sub Decrypt(ByVal inName As String, ByVal outName As String)
        Try
            Dim storage(4096) As Byte
            Dim totalBytesWritten As Long = 8
            Dim packageSize As Integer
            Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read)
            Dim fout As New FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write)
            fout.SetLength(0) …
discovery-power 0 Junior Poster in Training

Hi All,

I always have trouble with this every time I create a desktop app which needs to update data from a database.

So, I have created and coded my form to load data into a data grid view control, I can add data to the data grid view and it updates fine but when I come to delete a line, I get the error message below

System.InvalidOperationException was unhandled
  Message="Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information."

Please see below my code for the form.

Imports System.Data.SqlClient
Public Class Breakfast

    Dim conn As SqlConnection
    Dim breakfast As SqlDataAdapter
    Dim dsbreakfast As DataSet

    Private Sub Breakfast_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try
            conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=SlimmingWorld;Integrated Security=True")
            dsbreakfast = New DataSet
            breakfast = New SqlDataAdapter("SELECT RedorGreen,Name,Ingredients,Sins FROM Breakfast", conn)
            Dim cmdBuilder As SqlCommandBuilder = New SqlCommandBuilder(breakfast)
            breakfast.Fill(dsbreakfast, "breakfast")
            DataGridView1.DataSource = dsbreakfast.Tables("Breakfast")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub

    Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
        breakfast.Update(dsbreakfast, "breakfast")
    End Sub
End Class

I believe it's the update button code that's causing the problem.

Can anyone help.

Thanks

John

I forgott to add a primary key.

Sorted

discovery-power 0 Junior Poster in Training

Hi All,

I always have trouble with this every time I create a desktop app which needs to update data from a database.

So, I have created and coded my form to load data into a data grid view control, I can add data to the data grid view and it updates fine but when I come to delete a line, I get the error message below

System.InvalidOperationException was unhandled
  Message="Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information."

Please see below my code for the form.

Imports System.Data.SqlClient
Public Class Breakfast

    Dim conn As SqlConnection
    Dim breakfast As SqlDataAdapter
    Dim dsbreakfast As DataSet

    Private Sub Breakfast_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try
            conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=SlimmingWorld;Integrated Security=True")
            dsbreakfast = New DataSet
            breakfast = New SqlDataAdapter("SELECT RedorGreen,Name,Ingredients,Sins FROM Breakfast", conn)
            Dim cmdBuilder As SqlCommandBuilder = New SqlCommandBuilder(breakfast)
            breakfast.Fill(dsbreakfast, "breakfast")
            DataGridView1.DataSource = dsbreakfast.Tables("Breakfast")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub

    Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
        breakfast.Update(dsbreakfast, "breakfast")
    End Sub
End Class

I believe it's the update button code that's causing the problem.

Can anyone help.

Thanks

John

discovery-power 0 Junior Poster in Training

The usual procedure is to finalize the database design (table and column names, etc) then code to that design. If the database design is incomplete then you'll just have to modify your code as changes occur. The only other option (at leas as I can tell) is to abstract the column and table names. By that I mean store the column and table names in a config file and read those names in at run time. As an example, the config file might contain lines like

CustomerInfoTable = cust_info
ProductInfoTable = prod_info
CustomerNumber = cust_no

read those values into variables at load time then create your queries dynamically as in

query = "select " & CustomerNumber & " from " & CustomerInfoTable " where..."

At least that way you would only have to change the config file as the database changes (except for major restructuring)

Cheers Rev, sadley I am talking about database re structure and again you can only do it the long way round, like I did today, it took me 4 hours to add a couple of tables and change a column name, because I had to re-write the database in SQL Server Management Studio, then I had to implement the new database in my app. Never mind I guess some things are just meant to be done the long way round ;)

I like your idea about the config file though.

thanks again for your help mate.

John

discovery-power 0 Junior Poster in Training

Hi All,

I need some help in understanding something.

I have an existing database and I make some changes in Sql Server Management Studio, how can I adapt those changes in the Visual Basic project.

As an example if I change a table name in Sql Server Management Studio how can I update that change in my VB project.

OR

Can I update the database directly from Visual Basic.

Learning these skills would be a huge advantage for me.

Any help would be much apreciated.

Thanks very much

John

discovery-power 0 Junior Poster in Training

Take out the comma in ",FROM Breakfast".

Thank you, both of you, I normally use the "add data source wizard" but you can do so much more by actually writing the code, but the tiniest little thing can trip you up.

It supprises me that I had a syntax error and vb did not show an error in design time.

Thanks again for your help.

John

discovery-power 0 Junior Poster in Training

Hi All,

My wife is into the slimming world diet and has magazines with her favorite diets marked, so I decided to write her a desktop application so she can save all her recepies and tidy all those magazines.

So please see my code for my breakfast form below

Imports System.Data.SqlClient
Public Class Breakfast

    Dim conn As SqlConnection
    Dim breakfast As SqlDataAdapter
    Dim dsbreakfast As DataSet

    Private Sub Breakfast_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try
            conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=SlimmingWorld;Integrated Security=True")
            dsbreakfast = New DataSet
            breakfast = New SqlDataAdapter("SELECT RedorGreen,Name,Ingredients,Sins,FROM Breakfast", conn)
            Dim cmdBuilder As SqlCommandBuilder = New SqlCommandBuilder(breakfast)
            breakfast.Fill(dsbreakfast, "breakfast")
            DataGridView1.DataSource = dsbreakfast.Tables("Breakfast")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub

    Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
        breakfast.Update(dsbreakfast, "breakfast")
    End Sub
End Class

I am getting an error when I run the program that says "syntax error near the keyword FROM."

Please see below my sql database I wrote

USE [master]
GO
CREATE DATABASE SlimmingWorld
GO
USE SlimmingWorld
GO

CREATE TABLE [dbo].[Breakfast](
[RedorGreen][nvarchar](50) NULL,
[Name][nvarchar](50) NULL,
[Ingredients][nvarchar](50) NULL,
[Sins][nvarchar](50) NULL)

I have spent ages looking for the problem and I just can't see it, can anyone help.

Thanks

John

discovery-power 0 Junior Poster in Training

Hi All,

I am writing a program that saves quotes for writers to an xml file. Well I save my data to the xml file, but when I go to load the document I get this exception thrown at runtime.

System.Xml.Xsl.XslLoadException was unhandled
LineNumber=2
LinePosition=1
Message="Stylesheet must start either with an 'xsl:stylesheet' or an 'xsl:transform' element, or with a literal result element that has an 'xsl:version' attribute, where prefix 'xsl' denotes the 'http://www.w3.org/1999/XSL/Transform' namespace."
Source="System.Xml"
SourceUri="file:///C:/Users/John-Ellis/Documents/Visual Studio 2008/Projects/Assignment 6/QTR/QTR/bin/Debug/QTR.xml"

Please see my code below for the load button.

Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl
Imports System.Data.SqlClient

Public Class SearchQuotes
    Dim QuotesXmlDoc As XmlDocument
    Dim Loaded As Boolean
    Dim FileName As String

    Private Sub btnLoadQuotes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadQuotes.Click
        Dim od As New OpenFileDialog
        od.Filter = "XML Files(*.XML;)|*.XML"

        If od.ShowDialog = Windows.Forms.DialogResult.OK Then
            FileName = od.FileName
            QuotesXmlDoc = New XmlDocument()
            QuotesXmlDoc.Load(FileName)
            Loaded = True
            WebBrowser1.Navigate(FileName)

            'create the transform object
            Dim Transform As XslCompiledTransform = New XslCompiledTransform()
            Transform.Load(FileName)

            'create xml writer
            Dim Settings As New XmlWriterSettings
            Settings.CloseOutput = True
            Dim xWriter As XmlWriter = XmlWriter.Create("C:\Users\John-Ellis\Documents\Visual Studio 2008\Projects\Assignment 6\QTR\QTR\Quotes.xml", Settings)

            'tranformation
            Transform.Transform(QuotesXmlDoc, Nothing, xWriter)
            xWriter.Flush()
            xWriter.Close()
            WebBrowser2.Navigate("C:\Users\John-Ellis\Documents\Visual Studio 2008\Projects\Assignment 6\QTR\QTR\Quotes.xml")
        End If

    End Sub

I'm at a bit of a loss, any help would be greatly appreciated.

Thanks very much.

John

discovery-power 0 Junior Poster in Training

Hi Chilume,

Ok, I found this website, it looks like you can use winsock but you need to use a third party piece of software as well.

Here is the link: http://www.pcreview.co.uk/forums/run-unix-linux-shell-script-vbulletin-net-t3727521.html

Hope this helps mate.

John

discovery-power 0 Junior Poster in Training

I wanted to connect to unix and call a shell script program from dot net application (windows application).
do i need to use MS Winsock control to connect to unix or is there any other best option?
Kindly let me know.
Thanks

Hi Chilume,

When I used Unix a few years back, I never thought you could use the .net framework to run a Unix shell script.

I will have a sniff round google and let you know what I find but like I say from my past experience, .net is Windows and Unix is Unix.

John

discovery-power 0 Junior Poster in Training

HI John,

Thank you fir the reply... I followed the steps you suggested...

I have selected

Windows Installer 3.1

.NET Framework 3.5

IN prerequisite " Specify the install location for prerequisite
I selected " Download prerequisite from the components vendor's website" since other options gives me error while publishing... this time the publish was successful.
But when I try to install the set up on another system the following error messgae is displayed
" Unable to install or run the application. The application requires that assembly Microsoft VisualBasic.PowerPacks.Vs Version 9.0.0.0 be installed in the Global Cache (GAC) first. Please contact your system administrator. "

Please try your best to solve this...

regards,
Ashwin

Hi Ashwin,

I have done some research and there are two ways you can fix the problem, either of these should work.

1. Open the Properties page of your project.

2. click the References page.

3. Check the path of Microsoft.visualBasic.powerPacks.Vs.. In my case the path is:

C:\Program Files\Common Files\microsoft shared\Visual Basic Power Packs\1.1

4. Go to that folder you will find 2 files.

Microsoft.VisualBasic.PowerPacks.Vs.dll

Microsoft.VisualBasic.PowerPacks.Vs.xml

5. Copy these 2 files to the floder that you want to run your program at your friends PC

Do me a favour though, make a BACK-UP of your program before you start deleting things from your refernces.

Or you can

Go to project properties

click on publish tab

application files

discovery-power 0 Junior Poster in Training

I have already asked about the problem in java forum... Now i think the solution is only possible through microsoft products... Problem is i want to get the handle of a application and send commands to that application... Is it possible,, commands are send to combo box , text area, buttons etc..... Please help to solve this problem....

Hi Majestics,

I will help if I can, creating commands for objects such as buttons, combo boxes and so on are definatley possible with vb.net, exactley what is it you are having problems with.

Cheers

John

discovery-power 0 Junior Poster in Training

Hi Guys,

Thank you for the reply but I am still not able to create a setup for my project. When I try to use publish wizard i get the below errors ... In pre requisites I have given the following url
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=fe6f2099-b7b4-4f47-a244-c96d69c35dec&displaylang=en

Error 1 Cannot publish because a project failed to build. Lead_Management_Project

Error 2 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX\instmsia.exe' in item '.NET Framework 2.0 (x86)' can not be located on disk. See Help for more information. Lead_Management_Project

Error 3 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX\WindowsInstaller-KB893803-v2-x86.exe' in item '.NET Framework 2.0 (x86)' can not be located on disk. See Help for more information. Lead_Management_Project

Error 4 The install location for prerequisites has not been set to 'component vendor's web site' and the file 'DotNetFX\dotnetfx.exe' in item '.NET Framework 2.0 (x86)' can not be located on disk. See Help for more information. Lead_Management_Project

Please give me step by step solution for vb 2008 express edition ...

Hi Ashwin,

Ok, lets get some info on what your using to build and publish your program, what version of Visual Studio or Visual Basic are you using (2006 / 2008).

Lets say your using Visual Basic 2008 express

I am going to tell you what I use in my prerequisites, I was going to mention it last night but I thought you might …

discovery-power 0 Junior Poster in Training

Hi John,

Thank you for the reply.. I used the Publish method to create a setup file of my project. But I have another problem. When I try to install it in the other computer which does not have VB installed, it does not execute. It gives an error message something like files missing....
i am actually trying to create a set / installation file so that I can run and install my project / software on other computers ....

Hi Ashwin,

Im not sure why you cant run the program, all the publish wizard does is collect all your project files and compile them into a .exe, it also craetes the setup file, which you can either save on a server so other computers can download it or save to some kind of media (cd, dvd, data stick).

TRY THIS

Go back into properties, click on the COMPILE tab, then click on ADVANCED COMPILER SETTINGS, make sure that the TARGET CPU is set to ANY CPU and TARGET FRAMEWORK is set to .NET FRAMEWORK 3.5

Going through all the options I can see in VS2008 I cant see any other reason why your build shouldnt work.

What I will suggest is try the build / publish again and if you still get the error message, write down exactly what it says and post it back on here, if you cant publish the same project twice (I have never tried) then as before post …

discovery-power 0 Junior Poster in Training

Hi All,

I have just completed my project in VB 2008 express edition. Now I want the project to be converted to .EXE so that I can deploy it on other computer / laptop.

Could any one please help....


Regards,
Ashwin

Hi Ashwin,

First you need to go to the build menu option and build your project.

Then you need to right click your solution and select properties, in there at the bottom you find the tab PUBLISH, from there you can either run the PUBLISH WIZRARD or PUBLISH NOW and that will create the setup file where you can install it on any computer. (that runs windows)

It may be worth you reading up on this, there is a youtube video available, but there are settings you can change from the properties window for your solution.

Whichever you choose to use either PUBLISH WIZARD or PUBLISH NOW you need to put a destination for the setup file so you know where to find it.

You could also go to the release folder of your project which is usually kept in MyDocuments/VB08/Projects/.../BinRelease/... in there you will find the .exe file for you project.

Cheers

John

discovery-power 0 Junior Poster in Training

hi everyone,
i dont no much about vb.net ....i am php developer
i have just developed a mini application in vb.net
i wanted to know how to hide our application from appearing in task manager....help me guys with some code

Hi,

I found this link from the codeguru website, they have written code in there you should read.

http://www.codeguru.com/forum/showthread.php?threadid=406555

If I find anymore I will post them on.

Hope it helps

Cheers

discovery-power 0 Junior Poster in Training

Hi,

How is the information your searching stored? for examle is it stored in a database.

Cheers

John

discovery-power 0 Junior Poster in Training

Hi All,

I have started making applications that retrieve data from sql databases.

I write the database with Sql management studio then apply that database to my applicaton.

My question is, how can I make my applications more secure against hackers. Some applications store user names and passwords and personal information / finantial information and so on.

Any help and advise would be greatly appreciated.

Thanks very much

John

discovery-power 0 Junior Poster in Training

did you added your primary key column in this line of code

daAddressBook = New SqlDataAdapter("SELECT Name,HomeTellNumber,MobileTellNumber,BirthDay,Email,Address FROM Details", conn)

i mean to say in select command

No, the only way I know to add a primary key is through the dataset xsd file.

Would you mind telling me how to do it through code.

Thanks

John

discovery-power 0 Junior Poster in Training

For delete you have to define primary key in your table, I think you dont have any primary key in your table and you have select that column as well

Try this, I think it will help you

Hi,

Thanks for the reply, I added a primary key to my table already, I added it through the addressbookdataset.xsd file in my solutions explorer.

Any other thaughts welcome.

Thanks

discovery-power 0 Junior Poster in Training

Hello All,

I am writing my self a simple little address book application and I seem to be having some trouble with updating the dataset.

I have written the code and I cant see for any reason why it shouldnt work, but during run time, when I delete an entry and try to save the changes I get the following error.

Update failed dynamic sql generation for the delete command is not supported against a select command that does not return key column information.

I have never come accross this error before. Please see my code below.

Imports System.Data.SqlClient

Public Class AddAddress

    Dim conn As SqlConnection
    Dim daAddressBook As SqlDataAdapter
    Dim dsAddressBook As DataSet

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub AddAddress_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=AddressBookdb;Integrated Security=True")
            dsAddressBook = New DataSet
            daAddressBook = New SqlDataAdapter("SELECT Name,HomeTellNumber,MobileTellNumber,BirthDay,Email,Address FROM Details", conn)
            Dim cmdBldr As SqlCommandBuilder = New SqlCommandBuilder(daAddressBook)
            daAddressBook.Fill(dsAddressBook, "AddressBook")
            DataGridView1.DataSource = dsAddressBook.Tables("AddressBook")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
        Try
            daAddressBook.Update(dsAddressBook, "AddressBook")
            MessageBox.Show("Address Book Updated")
        Catch ex As Exception
            MessageBox.Show("Update Failed" & ex.Message)
        End Try
    End Sub
End Class

Any help on what has gone wrong would be much apreciated.

Thanks

John

discovery-power 0 Junior Poster in Training

Hi lolafuertes,

Sorry I thaught I marked this one as solved, thanks for the reply though.

Johno

discovery-power 0 Junior Poster in Training

Hi mogaka,

I think I fixed it, I need more users in the database to test the program but it looks like its sorted, please see my working code below

Private Sub MRMMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Me.Text <> "Meeting Room Manager - ADMIN" Then
            btnNewUsers.Enabled = True
            btnCurrentBookings.Enabled = True
        Else
            btnNewUsers.Enabled = False
            btnCurrentBookings.Enabled = False
        End If
    End Sub

Thanks for your reply

John

discovery-power 0 Junior Poster in Training

Hi All,

I want to add some admin privaliges to my program, its simple enough, when the user is logged in as admin certain buttons are enabled, when the user is logged in as anyone else, these buttons are disabled.

Please see my code below

Private Sub MRMMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Me.Text = "Meeting Room Manager - ADMIN" Then
            btnNewUsers.Enabled = True
            btnCurrentBookings.Enabled = True
        Else
            btnNewUsers.Enabled = False
            btnCurrentBookings.Enabled = False
        End If
    End Sub

the problem I have is that the buttons are disabled even when logged in as ADMIN.

I dont understand why this wont work it seems simple enough, can anyone see what I have done wrong.

Thanks very much

John

discovery-power 0 Junior Poster in Training
MRMMain.Text = cmbBoxUsers.TEXT

Spectacular

Thankyou very much

John

discovery-power 0 Junior Poster in Training

Hi All.

I have developed an application for booking meeting rooms. A user has to log in before he / she can use the system.

I want the user name of that user to be shown in the form.

I thaught this was easy.

Please see my code below for the log in form

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim cmd As New SqlCommand("Select Name,Password from Users Where Name = '" & cmbBoxUsers.Text & "' and password = '" & txtBoxPassword.Text & "'", conn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        If dr.Read Then
            MsgBox("Login Accepted")
            MRMMain.Show()
            Me.Dispose()
        Else
            MsgBox("Login Failed, Please Try Again")
            cmbBoxUsers.Focus()
            txtBoxPassword.Focus()
        End If

        MRMMain.Text = cmbBoxUsers
    End Sub

    
End Class

I am getting this error on the line "MRMMain.Text = cmbBoxUsers"

Value of type System Windows Forms ComboBox cannot be converted to string

can anyone help me out with this.

Thanks very much

John

discovery-power 0 Junior Poster in Training

Hi All,

I really need some help.

I have been asked to write a search screen for a rooms booking application.

I have kept the design nice and simple so all the user has to do is enter the dates they want to book a room for and the results are shown in a datagrid view, if no rooms are available for that date a message is shown.

I have absolutly no idea where to start with the code.

I have written the code for the connection to the sql database, but this is as far as I get, everything I have tried so far just hasn't worked.

Has anyone got any simple search program examples they could show me to help me understand what I need to write for my search screen.

I have been at this weeks, any help or advice would be much appreciated.

Thanks very much

John

discovery-power 0 Junior Poster in Training

***UPDATE***

After all this I found the solution.

Cheers

discovery-power 0 Junior Poster in Training

Hi All,

Hope evryone is well.

I have a program I have created for booking out conference rooms, I want to code a print button so the user can print the booking they have created on the booking form.

I have been stuck on this for about a week and its driving me mad.

I have used a print document method and bound my text boxes to it, but I am not getting the print out format correct.

For instance my form on the screen will look like this

3
12/01/2011
08:00
13:00
sales meeting

but on paper it comes out like this

312/01/201108:0013:00salesmeeting

this is my code

Dim str As String
    Dim f As Font
    Dim b As SolidBrush
    Dim lines As Integer
    Dim chars As Integer
    Dim strformat As StringFormat
    Dim printstr As String
    Dim ps As PageSettings = New PageSettings()
  'LOADS PRINT DIALOG BOX
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        PrintDocument1.DefaultPageSettings = ps
        str = BookingIDTextBox.Text & RoomIDTextBox.Text & UserIDTextBox.Text _
        & ReasonTextBox.Text
        PrintDialog1.Document = PrintDocument1

        If PrintDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            PrintDocument1.Print()
        End If

    End Sub
    'Part of the print sub procedure
    Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, ByVal e As PrintEventArgs) Handles PrintDocument1.BeginPrint
        Try
            f = New Font("Arial", 12)
            b = New SolidBrush(Color.Black)
            strformat = New StringFormat()
            strformat.Trimming = StringTrimming.Word
            str = BookingIDTextBox.Text & RoomIDTextBox.Text & UserIDTextBox.Text _
            BookDateTextBox.Text & StartTimeTextBox.Text & EndTimeTextBox.Text _ &      ReasonTextBox.Text …
discovery-power 0 Junior Poster in Training

Thanks for the help on this one adatapost. Things have worked out great.

Thanks again

John

discovery-power 0 Junior Poster in Training

I have just had a thought, is it because I am using the select command

Bookings = New SqlDataAdapter("SELECT BookingID,RoomID,UserID,BookDate,StartTime,EndTime,Reason FROM Bookings", conn)

Should I be using INSERT INTO

Bookings = New SqlDataAdapter("INSERT INTO BookingID,RoomID,UserID,BookDate,StartTime,EndTime,Reason FROM Bookings", conn)

I will test this theory tonight.

John

discovery-power 0 Junior Poster in Training

Thanks for the reply on that adatapost. I re wrote and fixed the error, however now my database won't update.

Please see my code below

Imports System.Data.SqlClient  

Public Class Form1  
Dim conn As SqlConnection  
Dim Bookings As SqlDataAdapter  

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load      

Me.BookingsTableAdapter.Fill(Me.MtrbookingsDataSet.Bookings)  

Try  

conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=mtrbookings;Integrated Security=True")  

conn.Open()  

Bookings = New SqlDataAdapter("SELECT BookingID,RoomID,UserID,BookDate,StartTime,EndTime,Reason FROM Bookings", conn)  

TextBox1.Text = "" 
TextBox2.Text = "" 
TextBox3.Text = "" 
TextBox4.Text = "" 
TextBox5.Text = "" 
TextBox6.Text = "" 
TextBox7.Text = "" 

Catch ex As Exception  

MessageBox.Show("CONNECTION FAILED" & ex.Message)  

End Try  

End Sub  

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click  

Form2.Show()  

End Sub      

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  

Me.BookingsTableAdapter.Update(Me.MtrbookingsDataSet.Bookings)  

End Sub  

End Class

I dont understand because I have put the update command in for the dataset.

Can anyone see what I have done wrong.

Thanks very much

John

discovery-power 0 Junior Poster in Training

Hi All,

I have created a form for a user to create a booking of a meeting room, I need this form to do 3 things.

have print functionality

update the new booking to a dataset

view the current bookings screen

I seem to be struggling with the second task, when I try and save my new booking I get this error

System.InvalidOperationException was unhandled
  Message="Update unable to find TableMapping['mtrbookings'] or DataTable 'mtrbookings'."

Please see the code for my form.

Imports System.Data.SqlClient
Public Class Form1
    Dim conn As SqlConnection
    Dim Bookings As SqlDataAdapter
    Dim dsBookings As DataSet
    Dim cmdBuilder As SqlCommandBuilder = New SqlCommandBuilder(Bookings)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=mtrbookings;Integrated Security=True")
            conn.Open()
        Catch ex As Exception
            MessageBox.Show("CONNECTION FAILED" & ex.Message)
        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Form2.Show()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        dsBookings = New DataSet
        Bookings = New SqlDataAdapter("SELECT BookingID,RoomID,UserID,BookDate,StartTime,EndTime,Reason FROM Bookings", conn)
        Bookings.Update(dsBookings, "mtrbookings")
    End Sub
End Class

My feeling is that I have not declaired any data sources, like a data grid view or the text boxes from which my information is typed by the user (text boxes).

Can anyone help.

Thanks very much

John

discovery-power 0 Junior Poster in Training

you know how you say, save to my settings, how do I do that through code, your database is very similar to my database and your right, this looks to be the easiest way.

this is the code for my login form

Imports System.Data.SqlClient
Public Class Form2

    Dim conn As SqlConnection
    Dim Users As SqlDataAdapter
    Dim dsUsers As DataSet

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Users.Update(dsUsers, "Users")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=Usersdb;Integrated Security=True")
        dsUsers = New DataSet
        Users = New SqlDataAdapter("SELECT UserID,Name,Password,Phone FROM Users", conn)
        Dim cmdBldr As SqlCommandBuilder = New SqlCommandBuilder(Users)
        Users.Fill(dsUsers, "Users")
        DataGridView1.DataSource = dsUsers.Tables("Users")

    End Sub
End Class

thanks

john

discovery-power 0 Junior Poster in Training

Hi All,

I have a log in form, I have had a couple of idea's.

When a user logs in I want his/her name to print on the top of the main form with the current date, the data for the login form is collected from a sql database (not sure if that is relevant).

also, I have a particular button on the main form I only want active when the Administrator logs in, if anyone else logs in I want the button inactive.

Can anyone give me some idea's on how to achieve the above.

Thanks very much

John

discovery-power 0 Junior Poster in Training

Please, can you be so kind to post the resulting commands?

Hi,

Ok, I sorted this out finally. I decided to scrap the drag and drop idea for the dataset and do it all through code (which as strange as it seems, was much easier).

I also gave the table I am using a primary key.

I added a datagridview control and 2 button controls to my win form, I use 1 button to fill the datagridview control with data from the selected table, I also use 1 button to update the dataset.

See my working code below.

Imports System.Data.SqlClient
Public Class Form2

    Dim conn As SqlConnection
    Dim Users As SqlDataAdapter
    Dim dsUsers As DataSet

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Users.Update(dsUsers, "Users")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=Usersdb;Integrated Security=True")
        dsUsers = New DataSet
        Users = New SqlDataAdapter("SELECT UserID,Name,Password,Phone FROM Users", conn)
        Dim cmdBldr As SqlCommandBuilder = New SqlCommandBuilder(Users)
        Users.Fill(dsUsers, "Users")
        DataGridView1.DataSource = dsUsers.Tables("Users")

    End Sub
End Class

Thanks for the help on this, im just glad its sorted now :)

Happy new year all.

John

discovery-power 0 Junior Poster in Training

Please, verify the line 18 of your code.
Maybe you need to change to

da.DeleteCommand = myBuilder.GetDeleteCommand

Hope this helps

Hi,

Thanks for the help, it still doesnt update though, do you think it could be something to do with my update commands??

Thanks

John

discovery-power 0 Junior Poster in Training

Hi All,

I have had some reall problems with this. I have a form with a datagridview, now I can add new records and the dataset will update fine, but it wont update when I want to delete a record.

Please see below my code.

Imports System.Data.SqlClient
Public Class Form2
    Dim da As SqlDataAdapter
    Dim conn As SqlConnection

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=mtrmanager;Integrated Security=True")
        conn.Open()
        Me.UsersTableAdapter.Fill(Me.MtrmanagerDataSet.Users)

    End Sub
       
    Private Sub UsersBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Try
            Dim myBuilder As SqlCommandBuilder = New SqlCommandBuilder(da)
            da.SelectCommand = myBuilder.GetDeleteCommand
            da.UpdateCommand = myBuilder.GetUpdateCommand
            da.Update(Me.MtrmanagerDataSet)
            Me.Validate()
            Me.UsersBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.MtrmanagerDataSet)

        Catch ex As Exception
            MsgBox("Updated Failed" & ex.Message)
        End Try

    End Sub

    Private Sub Form2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        conn.Close()
    End Sub

End Class

I dont actually get any design or runtime errors, the dataset just will not update. I have been into the configuration screen for the dataset and made sure that all the correct check boxes are selected.

Not sure what else to do? has anyone got any idea's.

Thanks

John

discovery-power 0 Junior Poster in Training

You can follow this link: (it is for MSAccess, but will let you know how to do that)
Instead of OLEDB Classes you can use SqlClient's Classes like:
SqlConnection
SqlCommand
SqlDataREader
etc.....
http://www.codeproject.com/KB/vb/InsertUpdateDeleteSearch.aspx

Cheers for that Shahan, it seems to me that its easier to hard code objects like update, delete and stuff like that rather than dragging the dataset from the wizard.

Thanks again for that.

John

discovery-power 0 Junior Poster in Training

Hi All,

I have created a form called new users, I have added my data source, draged over the objects I want from the dataset onto the form and all is well appart from the fact that I cant delete records.

To add them I simply click the add button, put in my info and then click the little disk button to update the dataset.

This does not work for the delete button though, instead I get the following error

UPDATE REQUIRES A VALID DELETE COMMAND WHEN PASSED DATA ROW COLLECTION WITH DELETED ROWS.

This is the code for my form.

Public Class NewUsers

    Private Sub UsersBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UsersBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.UsersBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.MtrmanagerDataSet)

    End Sub

    Private Sub NewUsers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'MtrmanagerDataSet.Users' table. You can move, or remove it, as needed.
        Me.UsersTableAdapter.Fill(Me.MtrmanagerDataSet.Users)

    End Sub
End Class

Can anyone give me a guide as to what code I need to use so I can delete recods and then update or save the current data.

Thanks very much.

John

discovery-power 0 Junior Poster in Training

Hi,

Thanks for he help. I came up with the code below.

Private Sub LoginForm1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=mtrmanager;Integrated Security=True")
        conn.Open()
        Dim dsUserName As New DataSet
        Dim UserName As SqlDataAdapter
        UserName = New SqlDataAdapter("select Name from Users", conn)
        Dim cmdBuilder As New SqlCommandBuilder(UserName)
        UserName.Fill(dsUserName, "Users")
        ComboBox1.DataSource = dsUserName.Tables("Users")
    End Sub

However when I run the app, the combobox shows:

"System.Data.dataRowView"

have I written the code wrong?

Thanks very much

John

Problem sorted, please see working code below.

Private Sub LoginForm1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=mtrmanager;Integrated Security=True")
        conn.Open()
        Dim dsUserName As New DataSet
        Dim UserName As SqlDataAdapter
        UserName = New SqlDataAdapter("select Name from Users", conn)
        Dim cmdBuilder As New SqlCommandBuilder(UserName)
        UserName.Fill(dsUserName, "Users")
        ComboBox1.DataSource = dsUserName.Tables("Users")
        ComboBox1.DisplayMember = "Name"
    End Sub

have a happy new year everyone :)

John

discovery-power 0 Junior Poster in Training

Hi!

>>>>I imagine I need to place this code in the form load event

It depends on your need when you want your combobox to fill. So, use appropriate event for that. Here is a Form_Load event sample code in a link that might help you:

http://social.msdn.microsoft.com/Forums/en/Vsexpressvb/thread/8844df20-9c56-47b5-8023-3d5b38d454d2

Also these two links will help you to proceed further: (read the details and check the code present at the end)

http://msdn.microsoft.com/en-us/library/system.windows.forms.listcontrol.displaymember.aspx

http://msdn.microsoft.com/en-us/library/system.windows.forms.listcontrol.valuemember.aspx

Hi,

Thanks for he help. I came up with the code below.

Private Sub LoginForm1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=mtrmanager;Integrated Security=True")
        conn.Open()
        Dim dsUserName As New DataSet
        Dim UserName As SqlDataAdapter
        UserName = New SqlDataAdapter("select Name from Users", conn)
        Dim cmdBuilder As New SqlCommandBuilder(UserName)
        UserName.Fill(dsUserName, "Users")
        ComboBox1.DataSource = dsUserName.Tables("Users")
    End Sub

However when I run the app, the combobox shows:

"System.Data.dataRowView"

have I written the code wrong?

Thanks very much

John

discovery-power 0 Junior Poster in Training

Hi All,

I have a combo box in a form, I want to fill it with names I have stored in a database.

I know I have to use the fill command, but I am not sure what code I need to use.

I imagine I need to place this code in the form load event, where I wrote my code to connect to the database.

Tell me if I am wrong, but, do I need to create a sql fill command, select Names From Users, then execute that command in the combo box object.

Any help would be much appreciated.

Thanks

John

discovery-power 0 Junior Poster in Training

in your project properties...
make sure formlogin1 is the startup form.
close application when all forms are closed

on button login_click

form1.show
me.dispose


on form1_formclosed

application.exit

THANKYOU THANKYOU THANKYOU - It works a treat, can't thankyou enough for your help on this one, finally I can close the chapter on this part of the project.

Thanks again mate

John

discovery-power 0 Junior Poster in Training

put a space between name and password...

is your user table name userid ?

I thought it was working for a second then but I just tried some incorrect details and it still logged me in, I have just seen your last post, yes I have missed that entire part of the code out, I swear I get blind as I get older.

Will keep you posted.

thanks

John

discovery-power 0 Junior Poster in Training

you are not comparing it..

on your form, in the ok button_click event

select username, password from users where username = " & txtusername.text & " and password = " & txtpassword.text & "

if rs.read
msgbox("GOOD")
continue..
else
msgbox("BAD")
continue
end if

Ok, I think I am getting somewhere, I am getting the error below.

System.Data.SqlClient.SqlException was unhandled
  Message="Invalid object name 'UserID'."

please see below my code

Imports System.Data.SqlClient
Public Class LoginForm1

    Dim conn As SqlConnection
    Dim rs As SqlDataReader

    Private Sub LoginForm1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=mtrmanager;Integrated Security=True")
        conn.Open()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        NewUser.Show()
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Application.Exit()
    End Sub

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

        Dim cmd As New SqlCommand("Select Name,Password from UserID", conn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        If dr.Read Then
            MsgBox("Login Accepted")
            Form1.Show()
            Me.Close()
        Else
            MsgBox("Login Failed, Please try Again")
            TextBox1.Focus()
            TextBox2.Focus()
        End If

    End Sub

End Class

Cheers

John

discovery-power 0 Junior Poster in Training

please mark as solved if you figured it out :P

not just yet, I went to bed to give my head a rest, back on it today, hopefully I will be able to mark as solved by the end of tonight.

Ta