Novo

Forum kao aplikacija na telefonu

Dodajte forum na početni ekran i koristite ga kao aplikaciju, sa menijem na dnu ekrana.

Ispis podataka pomoću DataReadera i dataGridViewa

  • 10 odgovora
  • 5.183 pregleda

Najnovija ↓

Ispis podataka pomoću DataReadera i dataGridViewa 12.12.2014. u 17:58 · pre 144 meseca #1
Želim da ispišem podatke iz tabele... Pokušala sam ovako ali neće da radi..


Code:

SqlConnection con = new SqlConnection(connstring);
            SqlCommand com;
            
            try
            {
                com = new SqlCommand();
                com.Connection = con;
                com.CommandText = "select * from table_name";
                con.Open();
                SqlDataReader reader = com.ExecuteReader();
                if (reader.HasRows)
                {
                    DataTable dt = new DataTable();
                    dt.Load(reader);
                    dataGridView1.DataSource = dt;
                }
            }
            finally
            {
                con.Close();
            }




Da li ima neko ideju? Hvala unaprijed..
Potpis
Follow your dreams, they know the way...
Re: Ispis podataka pomoću DataReadera i dataGridViewa 13.12.2014. u 15:29 · pre 144 meseca #3
Ovu gresku javlja..

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Potpis
Follow your dreams, they know the way...
Re: Ispis podataka pomoću DataReadera i dataGridViewa 13.12.2014. u 15:33 · pre 144 meseca #4
A, ako ukucam ovaj dio koda dataGridView1.DataBind(); javlja opet gresku..

Error 1 'System.Windows.Forms.DataGridView' does not contain a definition for 'DataBind' and no extension method 'DataBind' accepting a first argument of type 'System.Windows.Forms.DataGridView' could be found (are you missing a using directive or an assembly reference?)
Potpis
Follow your dreams, they know the way...
Re: Ispis podataka pomoću DataReadera i dataGridViewa 14.12.2014. u 01:36 · pre 144 meseca #6
Provjeravala sam putanju, fino je kopiram, ne znam samo da li ima veze je li u pitanju Local Database ili Service-Based Database? Ja pravim Local Database....
Potpis
Follow your dreams, they know the way...
Re: Ispis podataka pomoću DataReadera i dataGridViewa 14.12.2014. u 11:56 · pre 144 meseca #9
Hvala vam mnogo..

Jeste windows aplikacija.. Ali, nisam našla podforum za windows aplikacije, pa sam ovde postavila... Sorry.. Ovo je connection string... Da li je ok?
Code:

public static string connstring = @"Data Source=C:\Users\Korisnik\Desktop\5. SEMESTAR\INFORMACIONI SISTEMI Darko\Obracun_p\Obracun_p\Database1.sdf";
Potpis
Follow your dreams, they know the way...
Re: Ispis podataka pomoću DataReadera i dataGridViewa 14.12.2014. u 19:37 · pre 144 meseca #10
Ovo je zapravo connection string za sql server compact

Na prvi pogled deluje da je uredu, ali možda probaj da dodaš ; i pod navodnicima, ovako

Code:
public static string connstring = @"Data Source=C:\Users\Korisnik\Desktop\5. SEMESTAR\INFORMACIONI SISTEMI Darko\Obracun_p\Obracun_p\Database1.sdf;";


i pošto se koristi compact edition, mislim da treba koristiti odgovarajuće klase, tj. umesto SqlConnection koristiti SqlCeConnection, isto važi i za SqlCommand...
Sviđa mi se1
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme