[ damakii @ 08.02.2010. 20:43 ] @
Popunjavam bazu preko jedne forme u vb.net i prikazijem podatke u DatagridView. E sada, kada izbrisem jedan podatak ostaje rupa u ID broju (rednom broju) i pri sljedecem unosu taj broj se preskace. Npr. Ako sam izbrisao podatak na rednom broju 2 prilikom sljedeceg unosa novi podatak ce imati redni broj 3, a trebao bi imati 2. Kako da to napravim. Ovo je dio koda za dodavanje u bazu: Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If txt01.Text = "" Or txt02.Text = "" Or txt03.Text = "" Or txt04.Text = "" Or txt05.Text = "" Or txt08.Text = "" Or txt09.Text = "" Or txt10.Text = "" Then MsgBox("Sva polja za unos su obavezna osim polja 'Telefon 2' i 'Faks'") Else If kontrola Then Dim conna As New SqlConnection(My.Settings.conn) conna.Open() Dim sqlcommand As New SqlCommand("insert into operateri ([Naziv ugovornog organa],[Ime i prezime glavnog operatera],[Pozicija glavnog operatera],[E-mail],[Telefon 1],[Telefon 2],Faks,Username,Password,[Datum kreiranja]) values('" & txt01.Text & "','" & txt02.Text & "','" & txt03.Text & "','" & txt04.Text & "','" & txt05.Text & "','" & txt06.Text & "','" & txt07.Text & "','" & txt08.Text & "','" & txt09.Text & "','" & txt10.Text & "')", conna) sqlcommand.ExecuteNonQuery() MsgBox("Uspješno ste dodali novog glavnog operatera") Else Dim conne As New SqlConnection(My.Settings.conn) conne.Open() Dim sqlcommand As New SqlCommand("update operateri set [Naziv ugovornog organa]=N'" & txt01.Text & "',[Ime i prezime glavnog operatera]=N'" & txt02.Text & "',[Pozicija glavnog operatera]=N'" & txt03.Text & "',[E-mail]=N'" & txt04.Text & "',[Telefon 1]=N'" & txt05.Text & "',[Telefon 2]=N'" & txt06.Text & "',Faks=N'" & txt07.Text & "',Username=N'" & txt08.Text & "',Password=N'" & txt09.Text & "',[Datum kreiranja]=N'" & txt10.Text & "'where ID =" & DataGridView1.Item("ID", DataGridView1.CurrentRow.Index).Value, conne) sqlcommand.ExecuteNonQuery() MsgBox("Uspješno ste promijenili podatke o glavnom operateru") End If End If Dim operater As New DataSet1TableAdapters.operateriTableAdapter Dim dt As New DataTable dt = operater.GetData() Me.DataGridView1.DataSource = dt End Sub A ovo je dio koda za brisanje iz baze: Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim msg As String Dim title As String Dim style As MsgBoxStyle Dim response As MsgBoxResult msg = "Jeste li sigurni da želite izbrisati označenog operatera iz baze podataka?" style = MsgBoxStyle.YesNo title = "Upozorenje" response = MsgBox(msg, style, title) If response = MsgBoxResult.Yes Then Dim del As New DataSet1TableAdapters.QueriesTableAdapter del.DeleteQuery(DataGridView1.Item("ID", DataGridView1.CurrentRow.Index).Value) Dim operater As New DataSet1TableAdapters.operateriTableAdapter Dim dt As New DataTable dt = operater.GetData() Me.DataGridView1.DataSource = dt Else End If End Sub |