Hatman Δημοσ. 4 Ιουλίου 2007 Δημοσ. 4 Ιουλίου 2007 Kalhspera se olous. Tha hthela na kanw mia erwthsh oson afora to ADO.NET Yparxei kaneis pou na mhn kanei update thn database xrisimopoiontas sqlcommand alla allazontas ta data ston adaptor (px: da.Tables[0]Rows[0][0]="Hello") kai na kanei ginetai to update? Estw apo dataset h apo datatable... Den ginetai to update sto telos kai mou exoun liwsei ta neyra.. To palevw alla ola ta vivlia kai ta tutorials to kanoun kanontas instatiate ena command i mesa apo datagrid. Opoia vohtheia h estw ligos kwdikas eyprosdektos... (Mallon kati den kanw kala) Xilia eyxaristw....
Hatman Δημοσ. 4 Ιουλίου 2007 Μέλος Δημοσ. 4 Ιουλίου 2007 MySqlConnection thisConnection = new MySqlConnection(connString); MySqlDataAdapter thisAdapter = new MySqlDataAdapter( "select * from rates;", thisConnection); MySqlCommandBuilder thisBuilder = new MySqlCommandBuilder(thisAdapter); DataSet thisDataSet = new DataSet(); thisAdapter.Fill(thisDataSet, "rates"); Console.WriteLine("# rows before change: {0}", thisDataSet.Tables["rates"].Rows.Count); DataRow thisRow = thisDataSet.Tables["rates"].Rows[1]; thisDataSet.Tables["rates"].Rows[1].BeginEdit(); thisDataSet.Tables["rates"].Rows[1]["rname"] = "ZACZ"; thisDataSet.Tables["rates"].Rows[1]["rdate"] = "2007/07/07"; thisDataSet.Tables["rates"].Rows[1]["price"] = 11.11; thisDataSet.Tables["rates"].Rows[1].EndEdit(); thisDataSet.Tables["rates"].Rows[1].AcceptChanges(); thisDataSet.Tables["rates"].AcceptChanges(); thisDataSet.AcceptChanges(); Console.WriteLine("# rows after change: {0}", thisDataSet.Tables["rates"].Rows.Count); thisAdapter.Update(thisDataSet,"rates"); thisConnection.Close(); Ayto loipon den paizei. Den kanei Update. Ti leipei???? Ektos apo tulip... (to connectionstring den fainetai gia eynohtous logous. mhn mou pei kanenas to 3exasa...)
bilco Δημοσ. 4 Ιουλίου 2007 Δημοσ. 4 Ιουλίου 2007 Δεν έχεις ορίσει UpdateCommand για τον DataAdapter. Όρισε από τον CommandBuilder (προφανώς γιαυτό τον έφτιαξες) με την GetUpdateCommand
Hatman Δημοσ. 4 Ιουλίου 2007 Μέλος Δημοσ. 4 Ιουλίου 2007 Hehehe Vasika ayto emeine apo kei pou ekana copy kodika prin ton alla3w na kanei to update me rows.... Katse na doume me... Thx mate...
Hatman Δημοσ. 5 Ιουλίου 2007 Μέλος Δημοσ. 5 Ιουλίου 2007 Mpa tipota... Oute me : thisBuilder.RefreshSchema(); thisAdapter.UpdateCommand = thisBuilder.GetUpdateCommand(); Hmm.... Kamia idea?
bilco Δημοσ. 5 Ιουλίου 2007 Δημοσ. 5 Ιουλίου 2007 To παρακάτω δουλεύει > string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\bilco.mdb"; System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection(strCon); con.Open(); System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM BILCO_TABLE", con); DataTable dt = new DataTable(); da.AcceptChangesDuringFill = true; System.Data.OleDb.OleDbCommandBuilder cb = new System.Data.OleDb.OleDbCommandBuilder(da); da.UpdateCommand = cb.GetUpdateCommand(); da.InsertCommand = cb.GetInsertCommand(); da.DeleteCommand = cb.GetDeleteCommand(); da.Fill(dt); dt.Rows[1][1] = "bilcoR"; da.Update(dt); con.Close();
Hatman Δημοσ. 5 Ιουλίου 2007 Μέλος Δημοσ. 5 Ιουλίου 2007 > string strCon = "server=localhost;user=root;password=;database=equity;"; MySqlConnection con = new MySqlConnection(strCon); con.Open(); MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM RATES", con); DataTable dt = new DataTable(); da.AcceptChangesDuringFill = true; MySqlCommandBuilder cb = new MySqlCommandBuilder(da); da.UpdateCommand = cb.GetUpdateCommand(); da.InsertCommand = cb.GetInsertCommand(); da.DeleteCommand = cb.GetDeleteCommand(); da.Fill(dt); dt.Rows[1][0] = "bilcoR"; dt.AcceptChanges(); da.Update(dt); con.Close(); Console.Read(); Oute ayto grafei tipota sthn DB!!! (Xwris to dt.AcceptChanges(); petaei error) Ti na pw re filaraki... Eyxaristw poly pantws gia thn bohtheia... Mallon den paizei me tipota kai tha kanw ta updates me commands...
Προτεινόμενες αναρτήσεις
Αρχειοθετημένο
Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.