dimman24 Δημοσ. 31 Μαΐου 2015 Δημοσ. 31 Μαΐου 2015 Ειμαι παρα πολυ αρχαριος και στις 2 γλωσσες μα παρα πολυ εχω αυτο Imports System.Data.SqlClient Public Class _Default Inherits System.Web.UI.Page Dim mycon As String = "Data Source=THALIUS;Initial Catalog=my_db;Persist Security Info=True;User ID=sa;Password=mypass" Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim con As New SqlConnection Dim reader As SqlDataReader Try con.ConnectionString = mycon Dim cmd As New SqlCommand("SELECT * from pros where id=1", con) con.Open() ' Execute Query ' reader = cmd.ExecuteReader() 'CStr(reader(0)) 'reader.Item("ColumnName") While reader.Read() ListBox1.Items.Add(reader.Item("tayt") & " " & reader.Item("onoma") & " " & reader.Item("epitheto")) End While Catch ex As Exception MsgBox("Error while connecting to SQL Server." & ex.Message) Finally con.Close() 'Whether there is error or not. Close the connection.' End Try End Sub Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim con As New SqlConnection Dim reader As SqlDataReader Try con.ConnectionString = mycon Dim cmd As New SqlCommand("SELECT * from pros where id=1", con) con.Open() ' Execute Query ' 'reader = cmd.ExecuteReader() 'CStr(reader(0)) 'reader.Item("ColumnName") ???????????????????????????? Catch ex As Exception MsgBox("Error while connecting to SQL Server." & ex.Message) Finally con.Close() 'Whether there is error or not. Close the connection.' End Try End Sub End Class Ερωτηση πως καθε φορα που θα παταω το button2 θα μου εμφανιζει ενα ενα πεδιο? Δηλ. button2_click-->textbox1 = ΔΗΜΗΤΡΗΣ-->button2_click-->clear textbox1-->textbox1=ΜΑΚΗΣ
CtrlFreak Δημοσ. 31 Μαΐου 2015 Δημοσ. 31 Μαΐου 2015 Μέσα στο button2 βάζεις έναν μετρητή πχ i++ στο τέλος, τον καθαρίζεις όταν φτάσει τον αριθμό των γραμμών της βάσης, και κάνεις αναζήτηση στην βάση με βάση τον μετρητή. Πχ όταν το i=1 να επιστρέψει την εγραφή με id 1 όταν 2 κτλπ κτλπ..
dimman24 Δημοσ. 31 Μαΐου 2015 Μέλος Δημοσ. 31 Μαΐου 2015 Public Property count() As Integer Get Dim val As Object = ViewState("count") Return If(val IsNot Nothing, CInt(val), 1) End Get Set(ByVal value As Integer) ViewState("count") = value End Set End Property Αυτος ειναι ο κωδικας copy-paste (προσθεσα και ενα updatepanel μονος μου) αλλα δεν τον καταλαβαινω
dimman24 Δημοσ. 3 Ιουνίου 2015 Μέλος Δημοσ. 3 Ιουνίου 2015 Εχω εναν φιλο google στο ονομα....αστα αδερφε 2 μερες ψαξιμο....δε ξερω εαν ειναι σωστη λογικη κωδικα αλλα δουλευει και αυτο μου κανει! Εστω και αν κανει export την πιστωτικη μου...χαχα Imports System.Data.SqlClient Imports System.Security Public Class _Default Inherits System.Web.UI.Page Dim mycon As String = "Data Source=THALIUS;Initial Catalog=db;Persist Security Info=True;User ID=sa;Password=****" 'NA APO8HKEYETAI O COUNT SE OLH THN DIARKEIA Public Property count() As Integer Get Dim val As Object = ViewState("count") Return If(val IsNot Nothing, CInt(val), 1) End Get Set(ByVal value As Integer) ViewState("count") = value End Set End Property 'ARXH Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load dateLabel.Text = DateTime.Now.ToString() End Sub Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles nextButton.Click Dim con As New SqlConnection Dim reader As SqlDataReader Try Dim data_length As Integer = 0 con.ConnectionString = mycon Dim cmd As New SqlCommand("select * from pros where id=" & count, con) con.Open() ' ***EKTELESH QUERY ARXH reader = cmd.ExecuteReader() ' *** TELOS If reader.Read() = True Then bathmosBox.Text = reader.Item("77").ToString onomaBox.Text = reader.Item("onoma").ToString eponymoBox.Text = reader.Item("epitheto").ToString onoma_pateraBox.Text = reader.Item("onoma_patera").ToString onoma_mhterasBox.Text = reader.Item("onoma_miteras").ToString mitrowBox.Text = reader.Item("mitrow").ToString til_kin1Box.Text = reader.Item("til_kinito_1") til_kin2Box.Text = reader.Item("til_kinito_2") thl_statheroBox.Text = reader.Item("til_stathero") Else If count > 0 Then MsgBox("ΤΕΛΟΣ") Else count = count + 1 MsgBox("ooo") End If End If count = count + 1 Catch ex As Exception MsgBox("Error while connecting to SQL Server." & ex.Message) Finally 'MsgBox(GetUserName()) con.Close() 'Whether there is error or not. Close the connection. ' End Try ' End Sub Protected Sub saveBut_Click(sender As Object, e As EventArgs) Handles saveBut.Click Dim con As New SqlConnection Dim reader As SqlDataReader count = count - 1 Try Dim dateofuse As Date = DateTime.Now con.ConnectionString = mycon Dim cmd As New SqlCommand("update pros set 77='" & 77.Text & "',onoma='" & onomaBox.Text & "',epitheto='" & eponymoBox.Text & "',onoma_patera='" & onoma_pateraBox.Text & "',onoma_miteras='" & onoma_mhterasBox.Text & "',mitrow='" & mitrowBox.Text & "',til_kinito_1='" & til_kin1Box.Text & "',til_kinito_2='" & til_kin2Box.Text & "',til_stathero='" & thl_statheroBox.Text & "',date_of_use='" & dateofuse & "',user_modified='" & GetUserName() & "' where id=" & count, con) con.Open() ' Execute Query ' reader = cmd.ExecuteReader() count = count + 1 Catch ex As Exception MsgBox("Error while connecting to SQL Server." & ex.Message) Finally 'OTI KAI NA GINEI KLEINEI H SYNDESH ME THN BASH con.Close() End Try End Sub Private Sub reorder_id() Dim con As New SqlConnection Dim reader As SqlDataReader Try Dim data_length As Integer = 0 con.ConnectionString = mycon Dim cmd1 As New SqlCommand("ALTER TABLE pros DROP COLUMN id", con) Dim cmd2 As New SqlCommand("alter table pros add id int identity(1,1)", con) con.Open() ' Execute Query ' reader = cmd1.ExecuteReader() reader = cmd2.ExecuteReader() Catch ex As Exception MsgBox("Error while connecting to SQL Server." & ex.Message) Finally con.Close() 'Whether there is error or not. Close the connection. ' End Try End Sub Protected Sub backBut_Click(sender As Object, e As EventArgs) Handles backBut.Click Dim con As New SqlConnection Dim reader As SqlDataReader Try Dim data_length As Integer = 0 con.ConnectionString = mycon Dim cmd As New SqlCommand("select * from pros where id=" & count, con) con.Open() ' Execute Query ' reader = cmd.ExecuteReader() If reader.Read() = True Then bathmosBox.Text = reader.Item("77").ToString onomaBox.Text = reader.Item("onoma").ToString eponymoBox.Text = reader.Item("epitheto").ToString onoma_pateraBox.Text = reader.Item("onoma_patera").ToString onoma_mhterasBox.Text = reader.Item("onoma_miteras").ToString mitrowBox.Text = reader.Item("mitrow").ToString til_kin1Box.Text = reader.Item("til_kinito_1") til_kin2Box.Text = reader.Item("til_kinito_2") thl_statheroBox.Text = reader.Item("til_stathero") Else If count > 0 Then MsgBox("ΤΕΛΟΣ") Else count = count + 2 MsgBox("ooo") End If End If count = count - 1 Catch ex As Exception MsgBox("Error while connecting to SQL Server." & ex.Message) Finally con.Close() 'Whether there is error or not. Close the connection. ' End Try ' End Sub Function GetUserName() As String Dim nam As String = Principal.WindowsIdentity.GetCurrent().Name Return nam End Function Protected Sub newuserBut_Click(sender As Object, e As EventArgs) Handles newuserBut.Click End Sub End Class Δεν ειναι το τελικο αλλα για 15 μερες διαβασμα vb ειναι καλα πιστευω
CtrlFreak Δημοσ. 3 Ιουνίου 2015 Δημοσ. 3 Ιουνίου 2015 Άσε την VB και πιάσε κάτι άλλο... από γλώσσα εννοώ.
ALLisCHAOS Δημοσ. 4 Ιουνίου 2015 Δημοσ. 4 Ιουνίου 2015 Άσε την VB και πιάσε κάτι άλλο... από γλώσσα εννοώ. Όντως, γιατί όχι C#?
dimman24 Δημοσ. 6 Ιουνίου 2015 Μέλος Δημοσ. 6 Ιουνίου 2015 Όντως, γιατί όχι C#? Δε ξερω ετσι καθισε....τι να σου πω...java εγω ξερω αλλα δε με βολευει σε αυτα που θελω να κανω...ειμαι μεσα σε domain και ειναι λιγο περπλοκα τα πραγματα...C# δεν εχω διαβασει..........................ΑΚΟΜΑ χαχα
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα