Formulaire recherche stoquage en datagridview
Salut a tous et merci pour lire ma question!
J'ai un formulaire de recherche (voila le code) du boutton rechercher:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
Dim conexiune As SqlConnection 'conexiune cu sql server
'ne conectam la server name,user pass si nume_bd
conexiune = New SqlConnection("server=HOME-D16ABD96A8\PRIMAVERA;uid=mihaispr;pwd=mihai;database=ParcAuto")
conexiune.Open() 'deschidem conexiunea
'query-ul dorit pt.cautare in cele 2 tabele
Dim query As String = "SELECT tab1.NumarMasina, tab2.DataOraPlecare, tab2.DataOraSosire, tab2.LocalitatePlecare, tab2.LocalitateSosire " & "FROM tab1 LEFT JOIN tab2 ON tab1.IdMasina = tab2.IdMasina " & "WHERE tab1.NumarMasina = @NumarMasina " & "AND tab2.DataOraSosire BETWEEN @Date1Start AND @Date1End " & "AND tab2.DataOraPlecare BETWEEN @Date2Start AND @Date2End " & "AND tab2.LocalitatePlecare = @LocalitatePlecare " & "AND tab2.LocalitateSosire = @LocalitateSosire"
'variabile tampon pt. dataplecare si datasosire
Dim Data1 As Date = DateTimePicker1.Value.Date
Dim Data2 As Date = DateTimePicker2.Value.Date
Dim cmd As New SqlCommand(query, conexiune)
' parametrizare pt.formular cautare
With cmd.Parameters '2dtpickers si 3 textbox-uri
.AddWithValue("@NumarMasina", TextBox1.Text)
.AddWithValue("@Date1Start", Data1)
.AddWithValue("@Date1End", Data1.AddDays(1))
.AddWithValue("@Date2Start", Data2)
.AddWithValue("@Date2End", Data2.AddDays(1))
.AddWithValue("@LocalitatePlecare", TextBox2.Text)
.AddWithValue("@LocalitateSosire", TextBox3.Text)
End With
'creare dataset si apoi stocare in datagridview
'folosim metoda fill pt.completarea datagridview pornind
'de la dataset-ul da apartinand clasei SqlDataAdapter
Dim da As New SqlDataAdapter(cmd)
Dim table As New DataTable
Try
da.Fill(table)
DataGridView1.DataSource = table
'DataGridView1.Update()
'DataGridView1.Item(row_index,col_index)
'prinde cu catch eroarea
Catch ex As Exception
MsgBox(ex.Message)
'MessageBox.Show("Cautare fara succes!")
Finally
'inchidem conexiunea atunci cand stare conexiune=close
If conexiune.State <> ConnectionState.Closed Then
conexiune.Close()
End If
End Try
End Sub |
J'ai complete les 3 textboxes et 2 datetimepickers de ma forme en visual basic 2008 express. (textbox1 fais reference au tableau PatrimoniuMasini tab1 et le reste fais reference au deuxieme table FoaieParcursMasina les 2 textboxes et les 2 datetimepickers qui sont aussi completes).
Et je recois cette erreur dans l'interface graphique quand j'appuie le boutton chercher:
tab1 c'est l'alias pour table1 nomme PatrimoniuMasini et tab2 c'est l'alias pour table nomme FoaieParcursMasina.
Alors je ne sais pas comment definir tab1 et tab2 dans mon code du boutton de recherche.
C'est la mon souci:
http://img682.imageshack.us/img682/7230/eroare.png
J'ai essaye de definir tab1 et tab2 comme ca mais aucun succes:
Code:
1 2 3
|
Dim tab1 As DataTable
Dim tab2 As DataTable |
Si vous avez des idees je suis preneur!
Amicalment,
Michel