Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

vb.net problem sa rednim brojem u bazi

[es] :: .NET :: vb.net problem sa rednim brojem u bazi

[ Pregleda: 1211 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

damakii

Član broj: 136925
Poruke: 58
89.146.189.*



Profil

icon vb.net problem sa rednim brojem u bazi08.02.2010. u 20:43 - pre 173 meseci
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
damaki
 
Odgovor na temu

pals
Aleksandar Petrović
Slovenija

Član broj: 249834
Poruke: 9
..c.cable.static.telemach.net.

Sajt: https://webalpe.com


Profil

icon Re: vb.net problem sa rednim brojem u bazi08.02.2010. u 21:18 - pre 173 meseci
primer iz C#

List<int> listaId = new List<int>(); //lista koju punimo sa id iz tabele
int id = 0;
//ucitavanje Id korisnika
foreach (DataRow red in dt.Rows)
{
listaId.Add(Convert.ToInt32(red[1]));//id u tabeli je upisan u drugoj koloni
}
listaId.Sort();

//nalazenje najveceg broja Id korisnika
int najveciBroj = 0;
for (int i = 0; i < listaId.Count; i++)
{

if (listaId > najveciBroj)
najveciBroj = listaId;

}

int x = 0;
for (int i = 0; i < listaId.Count - 1; i++)
{
if (id == x & id != 0)
break;
x++;
for (int u = x; u < najveciBroj + 1; u++)
{
if (u == listaId)
break;
id = u;
break;
}
}
if (id == 0)
id = ++najveciBroj;


id je ta rupa
 
Odgovor na temu

[es] :: .NET :: vb.net problem sa rednim brojem u bazi

[ Pregleda: 1211 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.