hi guys ,
1)i wrote this bunch of codes but i can't get any result from part update . this part should update those cells that user want to change it.

for example you want to change some music ranking so you must duble click on data gide viwe to update that cell and this part of this code must do this but when i calling this function ,nothing happening ... but why ?

private void AddingToLibrrary(bool Updata)
        {
            OleDbConnection obj_Connection = new OleDbConnection
                (@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\History.mdb");

            OleDbCommand obj_Command = new OleDbCommand();

            obj_Command.Connection = obj_Connection;

            if (Updata == false)
            {
                obj_Command.CommandText = "INSERT INTO History (Name,Artist,Album,Address)" +
                    "values(@namefild,@ArtistFild,@AlbumFild,@AddressFild)";

                obj_Command.Parameters.AddWithValue("@namefild", MusicTitle);
                obj_Command.Parameters.AddWithValue("@ArtistFild", MusicArtist);
                obj_Command.Parameters.AddWithValue("@AlbumFild", MusicAlbum);
                obj_Command.Parameters.AddWithValue("@AddressFild", FileLoadingclass.FileName);

                obj_Connection.Open();
                obj_Command.ExecuteNonQuery();
                obj_Connection.Close();

                this.historyQTableAdapter.Fill(this.historyDataSet.HistoryQ);
            }

            else if (Updata == true)
            {
                obj_Command.CommandText = "UPDATE History SET Ranking WHERE ID = " + DGVHistory.RowCount.ToString();

                try
                {
                    int row_affected = obj_Command.ExecuteNonQuery();
                    this.historyQTableAdapter.Fill(this.historyDataSet.HistoryQ);
                    MessageBox.Show(row_affected.ToString(), "Update command result");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

thanks .

The update command is not right:

"UPDATE History SET Ranking WHERE ID = "

you need to spacify the value to set

"UPDATE History SET Ranking [B]= X[/B] WHERE ID = "

but 'X' is not a special thing that i want to add , 'X' is something that user adding to a special cell. how can i find that what user want to add ?

sample :
assume the valuse in textBox named txtValue so the command should be

"UPDATE History SET Ranking = "+ txtValue.Text+" WHERE ID ="

i've understood ! but it isn't a textbox , its a dataGideviwe cell .

for example : (this my table )
----------------------------
something|something|something|
----------------------------
something|this is X|something|
----------------------------
something|something|something|
----------------------------

i chenged that code to this :

obj_Command.Connection = obj_Connection;

            if (Updata == false)
            {
                obj_Connection.Open();

                DataRow obj_Datarow = obj_DataTable.NewRow();

                obj_Datarow["Name"] = MusicTitle;
                obj_Datarow["Artist"] = MusicArtist;
                obj_Datarow["Album"] = MusicAlbum;
                obj_Datarow["Address"] = FileLoadingclass.FileName;

                obj_DataTable.Rows.Add(obj_Datarow);
                obj_DataAdapter.Update(obj_DataTable);

                obj_Connection.Close();
            }

            else if (Updata == true)
            {
                obj_Connection.Open();
                obj_DataAdapter.Update(obj_DataTable);
                obj_Connection.Close();
                
                try { }
                catch (Exception ex)
                { MessageBox.Show(ex.Message); }
            }

what is problemm here with this code in line red .

Object reference not set to an instance of an object.

but when i removing part update, C# work correctly ! :icon_eek:

no one knows ?

if you need value from cell

tableObj.Rows[rowIndex][cellIndex]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.