Errore update database

mercoledì 20 dicembre 2006 - 13.02

bradipo Profilo | Newbie

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!

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 !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5