I am having a problem with my C# datagridview. When I add data into it, it doesnt auto update. And nothing I found online works to update the view for the user during runtime. I've used refresh(), update(), invalidate(). Nothing seems to work. Can anyone help me out with this problem??
USING .NET framework 3.0

Do you use any DataSource? You better be using it - like DataTable. And when you will do changes in datagridview, all changes will reflct in dataTable as well.

// CREATE SQL ADAPTER
SqlDataAdapter da = new SqlDataAdapter();

// HOLDING PLACE IN MEM
DataSet ds = new DataSet();

BindingSource tblBS = new BindingSource();

this is what im using.

So I got my datagrid to refresh using this statement:
da.Fill(ds);

BUT, unfortunately it does not populate my Date column in my datagrid. Here is my insert Date method:

    private void insertDate()
    {// insert date in specific member row

        insertDatetime = "UPDATE WaynokaLogger SET Date = @Date " + "WHERE AccountID =" + newString;

        da.UpdateCommand = new SqlCommand(insertDatetime, cs);

        da.UpdateCommand.Parameters.AddWithValue("@Date", SqlDbType.DateTime).Value = DateTime.Now;


        cs.Open();
        da.UpdateCommand.ExecuteNonQuery();
        cs.Close();
        da.Fill(ds);

Is there anyway I can get the date column to refresh or update so the datagrid columns in my datagrid, when refreshed, will reflect what was inserted into sql database?

Change sql query to:

insertDatetime = @"UPDATE WaynokaLogger SET Date = @Date WHERE AccountID = '" + newString + "'";

or use parametreized query:

insertDatetime = "UPDATE WaynokaLogger SET Date = @Date WHERE AccountID = @id";
da.UpdateCommand = new SqlCommand(insertDatetime, cs);
da.UpdateCommand.Parameters.AddWithValue("@Date", SqlDbType.DateTime).Value = DateTime.Now;
da.UpdateCommand.Parameters.AddWithValue("@id", SqlDbType.Int).Value = newString;

neither solution helped me out at all, but I still give you rep:) because you help me out quite a bit. But im pretty sure it has something to do with my insertDate method. Because when I add a member into my datagrid, it populates every column except the "Date" column. BUUUUUT, when I go into mySql and select * from my_table, the date shows in the correct column. :/ This is so disconcerting lol

In MS SQL Date is a keyword.
Not sure about MySQL but if it is the same then either:
1) Change your column name to something else.
or
2) Put [] around the column name in you command strings.
E.G UPDATE WaynokaLogger SET [Date] = @Date WHERE AccountID = @id

Thanks Nick but I got it to work. I just had to recall my display() and it worked like a charm. But am still giving you rep because of your answer:)

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.