Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
ASP.NET 2.0 / 3.5 / 4.0
Errore update database
mercoledì 20 dicembre 2006 - 13.02
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
bradipo
Profilo
| Newbie
12
messaggi | Data Invio:
mer 20 dic 2006 - 13:02
Ho una classe con dei metodi per mostrare i dati di un database mysql e modificarli
Ho implementato anche un metodo per l'update (che funzionava perfettamente con sqlexpress) ma mi da questo messaggio di errore:
Exception Details: System.IndexOutOfRangeException: There is no row at position 0.
la riga in cui è presente l'errore
Line 39: ds.Tables[0].Rows[0][1] = FirstName;
Line 40: ds.Tables[0].Rows[0][2] = LastName;
il metodo di update:
public void updateNames(string ID, string FirstName, string LastName)
{
string PubsConnStr = ConfigurationManager.ConnectionStrings["PUBSConnectionString"].ConnectionString;
MySqlConnection conn = new MySqlConnection(PubsConnStr);
string SelectSQL = "SELECT ID, FirstName, LastName FROM names WHERE ID=@ID";
MySqlDataAdapter adapter = new MySqlDataAdapter(SelectSQL, conn);
DataSet ds = new DataSet();
adapter.SelectCommand.Parameters.Add("@ID", MySqlDbType.Int16, 11).Value = ID;
adapter.Fill(ds, "names");
ds.Tables[0].Rows[0][1] = FirstName;
ds.Tables[0].Rows[0][2] = LastName;
MySqlCommandBuilder cb = new MySqlCommandBuilder(adapter);
adapter.Update(ds, "names");
}
**modifica**
cercando un po ho visto che il problema in genere si risolve con un costrutto if
scusate se sono una chiavica ma sono all'inizio!
ho provato a fare così
if ds.Tables[0].Rows.Count > 0 then
ds.Tables[0].Rows[0][1] = FirstName;
ds.Tables[0].Rows[0][2] = LastName;
End if
ovviamente non mi funziona!
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !