Will check both out, thanks for the help guys.
Begginnerdev 256 Junior Poster
Reverend Jim commented: Nice, simple, straightforward example. +8
Will check both out, thanks for the help guys.
Have you tried the .ToString() function?
Example...
TxtRate.Text = dt.Rows(0).Item(1).ToString
I am sorry......
I meant.....
TxtRate.Text = dt.Rows(0).Item(1)
I have a question.
Does anyone know of a way to scan an image into vb.net, and then save that image as a multipage tiff?
I would need a redistributable.
I have been looking for a library that will do this, but every one I have found does not meet my needs without costing $500 or more.
Does anyone have any suggestions?
You can try loading the form, without getting the id.
When the user clicks "Save" you will retrieve the id then save.
That way you can prevent what adam_k is talking about.
The only way to receive the same key would be if they both press the buttons at the same time.
Do you have a code snippet we can look at to help troubleshoot?
You will need to first create a connection to the database.
http://www.connectionstrings.com/
Database Code Sample
Then you will want to create a data table containing the values from the database.
You will then populate the combobox with the datatable column desired.
You will want to create a data table form the database.
Then you will use the selected index of the combobox to pull from the datatable.
Example...
Select Case cbMenu.SelectedItem
Case 1
TxtRate.Text = dt.Rows(0).Column(1)
......
This will get the value stored in the second column of the corrosponding table row.
Assuming the value is in the second column of the same table.
You will need to create table with an integer field with a default of 0.
On form_load you will want to pull the value from the database and add 1 to it.
On form_close you will want to save that value back to the database.
You can use my previous post here for the connection example.
You will do something like this:
'In the form load event.
sqlcmd = "SELECT curnum FROM table"
cmd = new OleDBCommand(sqlcmd,con)
'In the form close event.
sqlcmd = "UPDATE table SET curnum ='" & txtStudentID.text & "'"
cmd = new OleDBCommand(sqlcmd,con)
You can also use my previous post here for a quick overview of connecting to a database with an oledb client.
Which program are you using to create the setup script?
You need to pack the .exe in the setup, not the solution.
The .exe can be found in the project bin/release folder.
You will need to package all libraries that are not a commonly installed library too.
To do this, go to your project settings > references and set all references to copy local.
When you create your script for the setup, you will need to include these .dlls to the script.
Catching the right exceptions and then handling those exceptions properly is the best practice.
Roger, thanks for the help.
Likewise Reverend. Most people have their own 'flavor' they like the most. :)
Mine just happens to be OLEDB due to current situations which I cannot disclose....or I might have to break your legs.... lol jk
Hello everyone!
I am posting this code for anyone who may be having issues with connecting to a database. Feel free to use this code as you wish.
This will be using the OLEDB library.
'Imports
Imports System.Data.OleDb
Public Class Form1
'Declarations
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Dim sqls As String
Dim sqlcmd As String
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'In form_load event, but can be used on button click.
'For hard coded connection string
sqls = "Provider=SQLOLEDB;Datasource=YOURSERVERNAMEHERE;" & _
"Initial Catalog=YOURDATABASENAMEHERE;Integrated Security=SSPI"
'For dynamic connection string
sqls = "Provider=SQLOLEDB;Datasource=" & txtServerName.Text & ";Initial Catalog=" & _
txtDatabaseName.Text & ";Integrated Security=SSPI"
'Place all connection code in try/catch blocks.
Try
'Connect using the string we have just created
If con.State <> ConnectionState.Open Then
con.ConnectionString = sqls
con.Open()
End If
'Alternative way is:
If con.State <> ConnectionState.Open Then
con = New OleDbConnection(sqls)
con.Open()
End If
'Selecting everything from a database
sqlcmd = "SELECT * FROM tablename"
'Selecting a specific value when you have a reference
sqlcmd = "SELECT * FROM tablename WHERE columnname = referencevalue"
'Non hardcoded method
sqlcmd = "SELECT * FROM tablename WHERE columnname = '" & txtDataToSearchBy.Text & "'"
'Setting the command
cmd.Connection = con
cmd.CommandText = sqlcmd
'Alternative way is:
cmd = New OleDbCommand(sqlcmd, con)
'Querying the database
'Many differny ways.
'Returns number of rows
cmd.ExecuteNonQuery()
'Returns only the first column of first row.
cmd.ExecuteScalar()
'Builds a data reader with the current command.
cmd.ExecuteReader()
'Good …
Try
SQLstr = "INSERT INTO Users (Username,Password) VALUES '" & txtUsername.text & "','" & txtPassword.Text & "'"
Are you using any DBMS?
You can try:
'sqls is a string
'cmd is a command builder
sqls = "SELECT * FROM employees WHERE id = '" & textbox1.text & "'"
cmd = New CommandBuilder(sqls,connection)
If cmd.ExecuteNonQuery = False Then
MsgBox("ID not found")
End If
Have you tried:
If cmd.ExecuteNonQuery() = False Then
'Your code here
End If
The code above creates a structure, in the form of a class, then passes the string information into the class. It then builds the string and assigns the value to your settings with what ever string name you want it to be.
Then it saves.
To use this, build the class by using the Project > Add Class name it ClassConnectionBuilder. Save the code you have above into that class.
'Creating connection string
Imports System.Data.SqlClient
Public Class ClassConnectionBuilder
Public Shared Function ConnectionStringBuilder(ByRef Server As String, ByRef database As String, _
ByRef userid As String, ByRef password As String) As String
Dim sqlConnString As New System.Data.SqlClient.SqlConnectionStringBuilder() With {
.DataSource = Server,
.InitialCatalog = database,
.UserID = userid,
.Password = password
}
Return sqlConnString.ConnectionString
End Function
End Class
Then you can use the build by either importing it then using it or providing a full "path".
IE
'Imported
'Importing would be: Imports yourprojectname.ClassConnectionBuilder
SqlConnectionStringBuilder(string,string,string,string)
'Not imported
ClassConnectionBuilder.SqlConnectionStringBuilder
Hope this helps
You could try something like this:
My.Settings.GCRConnectionString = "new string info here"
My.Settings.Save()
If you are wanting ID's to be unique, you might want to think about making it a primary key. Thus making it not possible to have multiples. Then you can wrap your insert in a try catch, the client will handle the "No duplicate keys" message.
What hericles is saying is true. I have found this out the hard way.
You can do what archelle stated by this simple if statement.
If conn.State = ConnectionState.Open Then
conn.Close()
conn.Dispose()
End If
What kind of file are you trying to open?
Is it an office file, text file, datatbase, picture or what?
You could also write a tiny app with a text box. The user puts the sql command in the text box and presses a button. The button will fire off code that will bind the text string to a command and ExecuteNonQuery.
Can you post the code that is fired when the user changes the index?
Could wrap the whole thing in a while loop too.
Dim ex As String = ""
While ex <> "exit"
'your code here
Console.WriteLine("Type exit to exit the application")
ex = Console.ReadLine()
End While
Did you add the setting the My Project > Settings tab?
The above suggestion is correct, The program might also be terminating to fast for you to see.
Try wrapping the program with a while.
Like this:
Sub Main()
Dim uservalue As String
Dim ex As String = ""
While ex <> "exit"
Console.WriteLine("What football team do you support? Oldham, Manchester City, or Manchester United?")
uservalue = Console.ReadLine()
If uservalue = "oldham" Then
Console.WriteLine("Good lad latics!")
ElseIf uservalue = "Manchester City" Then
Console.WriteLine("BOOOOOOOOOOOOOOOOO!!!!")
ElseIf uservalue = "Manchester United" Then
Console.WriteLine("BOOOOOOOOOOOOOOOOO!!!!")
Else
Console.WriteLine("I DONT KNOW WHO YOU ARE!")
End If
Console.WriteLine("Type exit to exit the application")
ex = Console.ReadLine()
End While
End Sub
This allows you to loop through the program until you want to exit.
I have done as you have said above, but my only problem is that I need sql server native client to be bootstrapped too. Anyone know how to do this?
I have abandoned Inno Setup and I am using Install Shield. I have created the setup solution and added the files that are prerequisets, but how do I make it install when they are not present?
I have already used the new requirement wizard, the only thing you can do there is check if it is there, if not prompt the user.
I need to know how to force install if it doesn't exist on user's machine.
I have recently written a VB.NET application and I am stuck on the deployment.
I can't use the ClickOnce, because the program has to be installed on the machine under program files, therefore, I use InnoSetup.
My problem is that the application requires sqlclient and .net 4.0 to be installed, and I am EXTREMELY green to InnoSetup scripts.
Does anyone know how to make InnoSetup check to see if they are installed, if not install them without prompting the user?
I have searched high and low and can't find a relevent article to my needs. Some are for online downloading, when I need local downloading only, and others are for runtimes.
I just can't seem to find an article that shows how to install automaticly and silent.
Anyone have any ideas?
You can also do:
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Form2.Show()
Form2.TextBox1.Text = Me.TextBox1.Text 'Where Me references Form1 - the TextBox1 from Form1
End Sub
End Class
Are you creating X dynamicly during run time or is X a public variable that is created on form load?
You could store all your data in an array in the text boxes "TextChanged" event procedure. Then use a statement like:
Dim tmp As String
If (arrayname[i].getLength() = 8) Then
tmp = arrayname[i]
arrayname{i] = "0" + tmp
End If
looping through the array checking each value.
If you mean this:
http://www.componentfactory.com/product?id=3
Then no, it is not "Free".
It is just a 60 day trial.
You will need to the the reverse of what you did to get max.
ie. Look for lowest and compare for lowest value and store it in another temp.
Then compare the two after all calculations are completed.
Seperate your filters with ;
Thank you stultuske, I feared I was getting to complex with it.
Will will loop through the array. Comparing the current index with the next index. Whichever index is higher, you will need compare to the value stored in the temporary variable. If the value in the temp variable is higher, keep it. If not, then write the higher value in the temp.
Example.
if (array[i] > array[i + 1] && array[i] > tempvar)
{
tempvar = array[i]
}
else if(array[i + 1] > array[i] && array[i + 1] > tempvar)
{
tempvar = array[i + 1]
}
After you have looped through the array and stored the highest value, you can then use
if (array[i] == tempvar)
{
numofinstances += 1
}
Where numofinstances is the number of the occurances of that number. Loop through a second time, checking all the values.
You will need to compare the values in the array, storing the higest in a temp value.
After that then you will need to search the array for that value and increment a counter every time you find that value.
You could change int to long
long nbr1=0,nbr2=0,result=0,rest=0;
What Jim is saying is correct. You will have to clear the list every time you change the combo box. That way you have a "fresh piece of paper" to load the new data back on.
If you want a "watermark" on a form, you can use a label with the text color very close the the default form color.
If you wanted to limit the number of spaces, you can use Kothaisaravan's method, and incrememnt a counter every time they press the space bar. Then use an if statement with the counter = number and use the replace.