Hi,
I'm having some trouble trying to insert my gridview data into a table using store procedure.
Here's the scenario:
I have a dataset1 with a query that selects about 20 columns from left outer joins 3 views (lets call them A, B, C views) and 1 table (D table).
I created a gridview that fills the gridview that the dataset... of the 20 columns 3 are hidden.
On this D table, I have one column that the cells are empty. This is where we need to enter the data during runtime.
I created a store procedure that will insert 5 columns from the dataset (3 of the hidden columns, 1 visible, and 1 column where we need to enter the value during runtime) using parameters
On my dataset1 configuration, I added a query that will execute the store procedure (lets call it InsertPIWidthTable, which is D table)
Problem:
I got my gridview to populate the data, but can't seem to get what I entered in the cell to store in my D Table. It says there is no argument given that correspond to the required parameter, but I have all the parameter names correct... So I stuck. Help?
I attached screenshots of everything. Thank you!
This is my code:
private void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
IEditableObject editableObject = e.Row.DataBoundItem as IEditableObject;
if (editableObject != null)
{
editableObject.EndEdit();
}
DataRowView dataRowView = e.Row.DataBoundItem as DataRowView;
if (dataRowView != null)
{
this.vW_ProdPrintPageTableAdapter.InsertPIWidthTable();
}
6 Answers, 1 is accepted
It seems to me that you need to add the parameters to the stored procedure method. Here is how to get the values from the DataBoundItem:
private
void
RadGridView1_CellEndEdit(
object
sender, GridViewCellEventArgs e)
{
var row = (e.Row.DataBoundItem
as
DataRowView).Row;
var plantCode = row[
"PlantColumn"
];
var orNum = row[
"OrNum"
];
InsertPIWithTable(plantCode, orNum);
}
Let me know how this works for you.
Regards,
Dimitar
Progress Telerik
I'm still getting an error... now its picking on my productionWidth
in the table, the column name is width
in the gridview that column name is changed to "productionWidth" and binds to the field "width" in the table. (we have 2 different types of width showing in the gridview which is why I had to change the name)
That sure if this matters...
I figured it out! Thanks Dimitar! You gave me what I needed to figure it out.. I just needed to convert the object to string/decimal and it worked.. Thanks so much!
private void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
IEditableObject editableObject = e.Row.DataBoundItem as IEditableObject;
if (editableObject != null)
{
editableObject.EndEdit();
}
DataRowView dataRowView = e.Row.DataBoundItem as DataRowView;
if (dataRowView != null)
{
var row = (e.Row.DataBoundItem as DataRowView).Row;
var plantCode = row["plantCode"];
var ordNum = row["ordNum"];
var ordItem = row["ordItem"];
var machine = row["machine"];
var productionWidth = row["productionWidth"];
this.vW_ProdPrintPageTableAdapter.InsertPIWidthTable(Convert.ToString(plantCode),Convert.ToString(ordNum), Convert.ToString(ordItem), Convert.ToString(machine), Convert.ToDecimal(productionWidth));
}
I am glad that this works now. Do not hesitate to contact us if you have other questions.
Regards,
Dimitar
Progress Telerik