Could you provide a bit more information? what happens when the program refuses to run?
kvprajapati commented: Please read OP and then go for answer. -2
Could you provide a bit more information? what happens when the program refuses to run?
Can nobody help me?
Sorry to bump my own thread, but I really need to know how to do this :(
I'm currently in the process of creating a Windows application much like "Steam".
The problem I'm having is that I need to be able to add new games to the list which auto generates a button and the code behind it. I have no idea how to do this.
Can anyone help me?
Below is the code I used behind the buttons:
Private Sub btn_KaneLynch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKaneLynch.Click
Dim kane As String = "C:\Program Files (x86)\Steam\steamapps\common\kane and lynch dead men\Launcher.exe"
Try
Process.Start(kane)
Catch ex As Exception
MessageBox.Show(System.Runtime.InteropServices.Marshal.GetLastWin32Error())
MessageBox.Show(kane)
End Try
End Sub
I find that combobox.SelectedValue doesnt work very well with database updates.
I personaly use combobox.SelectedItem. Which sub are you having trouble with? paste just that one sub :)
When you say updating your DB, I assume you mean adding new records?
This is how i would do it;
Imports System.Data.OleDb
Public Class Form1
Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
' opens database
objconnect = New OleDbConnection
objconnect.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source = Northwind.mdb"
objcommand = New OleDbCommand
objcommand.CommandText = "INSERT INTO `Customers` (`CustomerID`, `ContactName`, `ContactTitle`, `Address`, `City`, `PostalCode`, `Phone`) VALUES ('" & TbCusID.Text & "', '" & TbCusName.Text & "', '" & CmboConTitle.SelectedItem & "' , '" & TbAdd.Text & "' , '" & TbCity.Text & "' , '" & TbRegion.Text & "' , '" & TbPhone.Text & "');"
objcommand.Connection = objconnect
'Open the connection
objconnect.Open()
' Execute's query
objcommand.ExecuteNonQuery()
' closes connection
objconnect.Close()
End Sub
End Class
Imports System.Data.OleDb
Public Class Form1
Private objconnect As OleDbConnection
Private objcommand As OleDbCommand
Private objreader As OleDbDataReader
Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
objconnect = New OleDbConnection
objconnect.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source = YOUR_DB.mdb"
objcommand = New OleDbCommand
objcommand.CommandText = "INSERT INTO `Customers` (`customer`, `phone`, `address`) VALUES ('" & txtcust.text & "', '" & maskedphone.text & "', '" & txtaddress.text & "')"
objcommand.Connection = objconnect
'Open the connection
objconnect.Open()
' Execute's query
objcommand.ExecuteNonQuery()
' closes connection
objconnect.Close()
end sub
end class
This will input everything into the database for you. All you have to do is change the first part of the SQL query to the field names in the table
for one, using the connection wizards are always harder than actually coding it yourself. It creates more problems than the worth of it, you will learn this in time.
One thing I found when I used to use the connection wizards were that when I'd use the SQL query builder, they would conflict and crash. The updating however, I used to copy & paste the wizard script into "input to database" form closing sub so it would reload the whole data grid.
With the whole changing in one place and not in the other, I have found this is because you are testing the program in debug mode of VS08 while using the wizard. Once you publish & build your program you will find that it will not happen.
Summary:
Its well worth the effort to hard code something rather than try to take the "easy" route because not only will it give you more power over whatever your programming, using wizards will always make it harder for you in the end.
the combo box in the SQL statement is wrong.
it should read:
sql = "Select Unit_Price from Inventory_Price where ITem_Code = '" & combobox.SelectedItem & "' And Ending_Date is null"
I hope this helps
sql = "Insert into `cupcakeDB`.`users` (firstname, lastname, DOB, phone, mobile, home, pobox, gender, city, username, password) values ('" & txtfname.Text & "', '" & txtlname.Text & "', '" & txtbirthdate.Text & "', '" & txtphone.Text & "', '" & txtmobile.Text & "', '" & txthome.Text & "', '" & txtpobox.Text & "', '" & rbgender.SelectedValue & "', '" & txtcity.Text & "', '" & txtnewuser.Text & "', '" & txtnewpass.Text & "')"
only other thing I can think of
the same error :$
sql = "Insert into `users` (firstname, lastname, DOB, phone, mobile, home, pobox, gender, city, username, password) values ('" & txtfname.Text & "', '" & txtlname.Text & "', '" & txtbirthdate.Text & "', '" & txtphone.Text & "', '" & txtmobile.Text & "', '" & txthome.Text & "', '" & txtpobox.Text & "', '" & rbgender.SelectedValue & "', '" & txtcity.Text & "', '" & txtnewuser.Text & "', '" & txtnewpass.Text & "')"
^^^^ try this ^^^^
I'm not particularly up to scratch with SQL.
When inputting dates I've always used them as "date" in the database, but as a string in the program. Try without the hash and see what happens.
ok: update!
I've decided to use a .cfg file and using 'streamwriter' to create it.
I've used the following code to create my file:
Using sr As StreamWriter = New StreamWriter("dbpath.cfg")
sr.Write("db =" & db)
End Using
Im using pretty much the exact same code in form_load to read the file, but am unsure how to get the program to read whats in the .cfg as actual code.
Any ideas please?
sql = "Insert into users (firstname, lastname, DOB, phone, mobile, home, pobox, gender, city, username, password) values ('" & txtfname.Text & "', '" & txtlname.Text & "', #" & txtbirthdate.Text & "#, '" & txtphone.Text & "', '" & txtmobile.Text & "', '" & txthome.Text & "', '" & txtpobox.Text & "', '" & rbgender.SelectedValue & "', '" & txtcity.Text & "', '" & txtnewuser.Text & "', '" & txtnewpass.Text & "')"
whats with the hashes (#)? this is your problem. Replace them with the required syntax (')
There is always a need for a primary key.
Typically I always create an auto incrementing "ID" field which for each input from the program so you dont need to include it in the INSERT sql statement.
This also allows you to record how many records there are, search by ID number and easily identify identicle records.
That can be solved through the Access database itself. Look in the design view of the table and in the field properties you can set a primary key or set that particular field to allow null values
Here is my problem.
I'm creating a program for my workplace which stores hours worked, calculates pay and all that stuff.
Problem being, the database will be accessed through the network and i want to be able to select the database from an openfile dialog on first use to locate the database. On every program start up it then would have the database location stored within the program itself.
Now, the reason for the post;
What is the best way of doing this?
There are many different ways of doing the same thing in programming, which is the most practical of storing application settings?
Thank you in advance
dTx
steveneaster: Datatable is a function to do with the database controls not a table.
Aldius: Its a bit long winded, but one way you could do this is through comma delimited view in a text box. You can read from the field names and input them into variables and use the variable in an SQL statement input into the database
Thank you Ketsuekiame :)
I will try this straight away!
I hope you can help me. I'm working on a program that will open any Access database that might be on the system.
The problem I'm having is that I cant get get the SQL statement to show all the tables within the database.
The code im using is as follows:
Imports System.Data.OleDb
Public Class frmtables
Dim objconnect As OleDbConnection
Dim objcommand As OleDbCommand
Dim objreader As OleDbDataReader
Dim file As String
Dim sql As String
Private Sub frmtables_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
file = Form1.txtpath.Text
objconnect = New OleDbConnection
objconnect.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & file & ""
objcommand = New OleDbCommand
sql = "SELECT * FROM SYSCAT.TABLES"
objcommand.CommandText = sql
objcommand.Connection = objconnect
objconnect.Open()
objreader = objcommand.ExecuteReader
cmbotable.Items.Add(objcommand)
objconnect.Close()
End Sub
End Class
Now. After about two days of googling looking for that SQL statement, all it seems to do is look for "SYSCAT.mdb" instead of the database selected from the "Open File Dialog" of the previous form :(
Please Help.
Thank you in advance, Detoxx
Edit: I've also used
"USE '" & file & "' GO SELECT * FROM (sys.Tables) GO"
and
"SELECT * FROM INFORMATION_SCHEMA.TABLES"
USE YourDBName
GO
SELECT *
FROM sys.Tables
GO
hope this helps
Hi there.
My problem is that when i click play to resume a paused song it starts the song from the beginning.
I added an IF statement to the play button to say basically ...
IF PAUSED THEN PLAY (RESUME)
ELSE
PLAY FROM IMPORT LIST.
The problem with the IF statement, is that it says the pause command has no value.
For the life of me, i cannot figure out the IF statement. Please help
Public Class MP3Form
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles importDiag.FileOk
For Each track As String In importDiag.FileNames
Playlist.Items.Add(track)
Next
End Sub
Private Sub btnimport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnimport.Click
importDiag.ShowDialog()
End Sub
Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
If AxWindowsMediaPlayer1.Ctlcontrols.pause() = True Then
AxWindowsMediaPlayer1.Ctlcontrols.play()
Else
AxWindowsMediaPlayer1.URL = Playlist.SelectedItem
End If
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stopbutton.Click
AxWindowsMediaPlayer1.Ctlcontrols.stop()
End Sub
Private Sub pausebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pausebutton.Click
AxWindowsMediaPlayer1.Ctlcontrols.pause()
End Sub
End Class
thanks everyone, but i have solved it :)
public class Travel {
public static void main(String[] argv) {
// put your local declarations here
final double SPEED = 85;
double Distance = 0.0;
long Seconds;
long Minutes;
long Hours;
// Prompt and read the distance
UserInput.prompt("Type the travel distance: ");
Distance = UserInput.readDouble();
// Compute and print
Seconds = (long) ( Distance * 3600 / SPEED );
System.out.println ( "To travel " + Distance + " takes " + Seconds
+ " seconds" );
Minutes = Seconds / 60;
Seconds %= 60;
Hours = Minutes / 60;
Minutes %= 60;
System.out.println ( "To travel " + Distance + " takes "
+ Hours + " hours " + Minutes + " minutes " + Seconds
+ " seconds" );
} // end of main
} // end class
thank you again for all your help.
much appreciated.
http://img386.imageshack.us/my.php?image=questionfl0.jpg
this is the question i had to do to clear up anything.
I cant see how i can use If's and Else if to perform that tho ... a formula would do it for you :S
its the same as above ....
only thing is i changed the floats (hour, min, sec) to int.
//variables
final float KPH =85;
float distance;
int sec;
float min;
float hour;
float subtot;
[img]http://img230.imageshack.us/my.php?image=javaza8.jpg[/img]
I tried using the modulo and i still get decimals.
I also tried changing my some of my floats to integers, but my compiler will not let it compile as it says "Possible Loss of Precision"
is there anyway around this?
p.s I changed the hour, min and sec to int
Thank you for your posts!! it is really appreciated :)
i will give it a go and let you know how it turns out.
thanks again :D
Can anyone help me please? i need to create a program in which you enter a distance and the program will tell you how long it will take to get there in hours minutes and seconds.
My trouble is that they all display independently and not seperately ... for example ... i want it to display "1 hour 20mins 4 seconds" instead of "1.20 hours 80 mins" and how ever many in seconds.
thank you in advance for your help :)
public class Travel{
public static void main (String [] argv){
//variables
final float kph =85;
float distance;
float sec;
float min;
float hour;
float subtot;
// float total;
// float grandtot;
// prints out user prompt
System.out.println("Please Enter the Distance: ");
distance = UserInput.readFloat ();
// formula to work out length of travel
subtot = distance/kph;
// hour = subtot%10;
// total = distance/kph*60;
// min = total%10;
// grandtot = distance/kph*60*60;
// sec = grandtot%10;
min = subtot*60;
hour = min % 60;
sec = min*60;
//total= subtotal*60;
// total = distance/kph;
//timeInMin =
System.out.println("Time in Hours: "+hour);
System.out.println("Time in Minutes: "+min);
System.out.println("Time in seconds: "+sec);
System.out.println("The Total Time is: "+hour+":"+sec+":"+min);
}
}
well what you had entered in the last post has helped me so much :D
thank you very much!! i shall pass this year now thanks to you :P HND here i come!! <3
well what you had entered in the last post has helped me so much :D
thank you very much!! i shall pass this year now thanks to you :P HND here i come!! <3
thank you, it has helped quite alot.
my only problem is, now i have to input code so it asks for student ID's. would i have to enter something like
write('Enter Student Mark ');
readln(Marks[Student_Id,Student_Mark]);
but before that loop put
write('Enter Student ID')
readln(Marks[Student_mark,Student_Id]);
like swap the student_mark and student_id around in the square brackets for it to store under a ID instead of marks?
Hi, im new to this forum, and searched for everything to do with 2D array, but found nothing to no real avail.
My problem is that i have to write a 2D array in pascal that stores 15 student ID's and 5 marks for each student. I've managed to write out about 60% of it, but it fails to work as i think i've instructed it.
Heres the code:
program array2d;
uses crt;
var
Marks : array[1..5,1..15] of integer;
Student_Id : integer;
Student_Mark : integer;
Procedure Input;
begin
for Student_Id := 1 to 15 do
begin
for Student_Mark := 1 to 5 do
begin
write('Enter Student Mark ');
readln(Marks[Student_Id,Student_Mark]);
end;
end;
end;
Procedure Output;
begin
for Student_Id := 1 to 15 do
begin
for Student_Mark := 1 to 5 do
begin
write(Marks[Student_Id,Student_Mark],' ');
end;
writeln;
end;
end;
begin
clrscr;
Input;
Writeln;
Output;
writeln;
readln;
end.
Problem being is that it asks for 75 marks for each student but not in any particular order, it doesn't actually ask for the student ID's. I know this is missing from the code, but I'm stuck as to what to enter. It all has to be in "Incredibly Basic" tags as I'm a first year student. This confuses me so much, Please Help!!! it would be greatfuly appreciated!
p.s. sorry for asking a silly question :P