Please look to my source attached and download it and please read carefully my post!
Now I will explain what I've done and what I don't know how to do with details.
I have done a gui using visual basic6 which provides me entering datas in textbox.
I have two forms.
Form1 has 2 buttons (the button left makes the link with form2 and the second button exits the form1).
Now on Form2 I have:
and 2 buttons :
Urmatoarea Inregistrare - deletes all the content of my formular that contains 12 labels and 12 textbox so it deletes the content of my textboxes every time I entering text in the 12 textboxes. When I press the button Urmatoarea Inregistrare automatically the 12 textboxes becomes empty.
Until now everything it's perfect.
The thing I want to do is to implement the code of the button Salveaza date. (here is my problem)
I complete the fields in the 12 textbox and when I press the button Salveaza Date I want to complete the structure from this table created with SQL Server:
CREATE DATABASE ParcAuto CREATE TABLE FoaieParcursMasina (IdFoaie int PRIMARY KEY NOT NULL, DataFoaieParcurs datetime, IdMasina int, DataOraPlecare datetime, DataOraSosire datetime, NumeSofer varchar(255), LocalitatePlecare varchar(255), LocalitateSosire varchar(255), KM int, CombustibilConsumat int MotivDeplasare varchar(255), MarfaTransportata varchar(255), Utilizator varchar(255) )
So I want to insert first row in table FoaieParcursMasina when I complete the 12 values of my textboxes that lies on form2 of my vb6 form gui (except combustibilconsumat that is not in my vb form as you can see) so that he knows when I press the button Salveaza Date to save my first 12 values of my vb form into my table FoaieParcursMasina (done with CREATE TABLE).
I don't want to insert rows into table FoaieParcursMasina using SQL Server and INSERT INTO clause! I want to insert the datas provided in my 12 textboxes to the fields of my table in SQL Server . The labels are identically with field of the table of SQL Server FoaieParcursMasina as you can see. So everytime the user completes the fields in textbox(IdFoaie,etc) the fields are completed in my sql server table.
So the container of Label1 IdFoaie (which is listbox if I type 1) in IdFoaie field(first field from sql server table FoaieParcursMasina) to be completed automatically with 1 when I press the button Salveaza date from vb6 gui.
Also when I complete the rest of the textboxes the label has the same name as the field in my table if you look .
I want to insert rows when I complete the 12 values from my textbox and I press the button Salveaza Date from my vb6 gui.
I attach here the full project:
Here is the DDL for the table that I've created with SQL Server. When I press the button Salveaza Date all the datas contained by the textboxes of my vb6 form will be automatically completed in my table FoaieParcursMasina of SQL Server.
Hope I detailed well my problem (so I want to insert rows from vb6 to
CombustibilConsumat will not be completed it will remain a cell empty in table FoaieParcursMasini of SQL Server, I haven't CombustibilConsumat in my form vb6 as you can see. (so it's the only field I haven't put in my form vb6 for some reasons.
As you can see the name of labels are the same of the fields of FoaieParcursMasina that is created in SQL Server using CREATE TABLE command.
Hope I detailed well my problem!
Here's the code tried in Salveaza Date of Form2:
Private Sub Command2_Click(Index As Integer) 'Imports System.Data 'Imports System.Data.SqlClient Public Class account 'conexiune -variable used for connection with database 'comandasql - variable for sql query to insert values from textboxes in field of table 'FoaieParcursMasina 'citestedate variable used for readdata 'ra variable used for a new inserted row in the table (when I delete the containing of textboxes and complete again the 12 textboxes for the second row and when I press button Salveaza Date it adds the second row to my table). Dim conexiune As SqlConnection Dim comandasql As SqlCommand Dim citestedate As SqlDataReader Dim ra As Integer 'pt.un rand nou introdus conexiune = New SqlConnection("server=localhost;uid=mihaispr;pwd=mihai;database=ParcAuto") conexiune.Open() comandasql = New SqlCommand("insert into FoaieParcursMasina([IdFoaie],[DataFoaieParcurs],[IdMasina],[DataOraPlecare],[DataOraSosire],[NumeSofer],[LocalitatePlecare],[LocalitateSosire],[KM],[MotivDeplasare],[MarfaTransportata],[Utilizator]) values ('" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text & "','" & Text4.Text & "','" & Text5.Text & "','" & Text6.Text & "','" & Text7.Text & "','" & Text8.Text & "','" & Text9.Text & "','" & Text10.Text & "','" & Text11.Text & "','" & Text12.Text & "')", conexiune) mycommand.ExecuteNonQuery() MessageBox.Show ("New Row Inserted" & ra) conexiune.Close() End Sub End Class End Sub
What I want the value types by user in textbox1 (text1.text) to be added to IdFoaie column of table FoaieParcursMasina from sql server, then
value typed by user in vb6 form in textbox2 so text2.text to be added in DataFoaieParcurs from table FoaieParcursMasina in sql server, value typed by user in vb6 form in textbox3 so text3.text to be added in IdMasina field from table FoaieParcursMasina in sql server.
And so on.
On every press of the button it insert rows in table FoaieParcursMasina (so all textboxes must be completed).
I gave above the code I don't know what I'm missing truly.
This post has been edited by mihaispr: 07 November 2009 - 11:09 AM