Hello, Can anybody tell me if is it possible ( and if is, how to achive it ? ) adding new row to UltraGrid and user will have an option SAVE. if user clicks on Save It will automatically Update in the database. (at runtime).
I enabled option Adding new Row for the UltraGrid.So i'm able to add new row to UltraGrid. But i want to know how to Save that row in Database?
Any help is appreciated..
Thanks,
Best regards,
Sankar
Hi Sankar,
The grid only deals with the local data source. The interaction between the data source and that back end (the database) is outside of the grid's purview.
So how you update your database depends on what kind of data source you are using. If your data source is a DataSet, then the typical way to update to back end would be to use a DataAdapter.
Hi Mike,
Thanks for your advice.
In my appliction Datasource for UltraGrid is Dataset. (I am
Then at runtime user will enter newrow to the UltraGrid.That row will be updated in the database.
How can i do it? Can you please provide some links/code for this? I'm new to this concept.
Thanks in advance.
If you get Murach's Visual Basic 2005 book it is very good to show how to do this. When I add a row to the grid I use the update command to add the row to the local datasource then use a sql update command to add it to the database. It's a little more programing I think but I like to see whats going on and I learned it before the data adapter so it just saves learning something else.
Hi Morrisd,
I follow that book and add code for my application as follow
Update_Click Event():
{
if (ds.HasChanges()) { da.Update(ds.Tables["tblDeals"]); }
}
Then I got the Error: Update Requires a valid InsertCommand when passed DataRow collection with new rows.
Can u please help where i have to write Insert Statement and i can pass that values(user entered at runtime in the UltraGrid).
Thanks in advance,
Best Regards,
Apart from adding new row and saving are you updating/modifying the existing grid? if so then you need to use both update as well as insert command. If you are only concerned with the new row, then just use Insert command, since the new row is considered as an insert.
It's suggested to have a stored proc or just adhoc query below to insert to db
' Create the SelectCommand. Dim command As SqlCommand
' Create the InsertCommand. command = New SqlCommand( _ "INSERT INTO Customers (CustomerID, CompanyName) " & _ "VALUES (@CustomerID, @CompanyName)", connection)
' Add the parameters for the InsertCommand. command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID") command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName")
adapter.InsertCommand = command