Obtaining a Visual Studio 2005- SQL Server 2005- Databind Solution

Greetings,

I've been struggling with Aspose.Grid.Web. The demo samples are all in VB.Net using Visual Studio 2003. Only the Wiki examples are helpful in understanding how databinds work. The demo source code is far to complicated.

The Wiki examples for Aspose.Grid.Web demonstrate how to perform databinds using Access DB with Visual Studio 2003. Using Visual Studio 2005 with SQL Server 2005 is quite a bit different. Although I was able to load data using Visual Studio 2005 and SQL Server 2005, I can't get the save to work properly. Here is the relevant C# code:

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

//Checking if there is not any PostBack

if (!IsPostBack)

{

try

{

bcp_BusinessProcessTableAdapter bpta = new bcp_BusinessProcessTableAdapter();

//Filling DataSet with data

bpta.GetData();

//Binding GridWeb with DataSet

GridWeb1.DataBind();

}

finally

{

//Finally, closing database connection

//SqlDataSource1.Close();

// the Close method is not valid. Is it necessary to close the

// SqlDataSource1?

}

}

}

protected void GridWeb1_SubmitCommand(object sender, EventArgs e)

{

try

{

bcp_BusinessProcessTableAdapter bpta = new bcp_BusinessProcessTableAdapter();

//Getting the modified data of worksheet as a DataSet

DataSet1.bcp_BusinessProcessDataTable dataset = (DataSet1.bcp_BusinessProcessDataTable)GridWeb1.WebWorksheets[0].DataSource;

//Updating database according to modified DataSet

bpta.Update(dataset);

}

finally

{

//Finally, closing database connection

//SqlDataSource1.Close();

// the Close method is not valid. Is it necessary to close the

// SqlDataSource1?

}

}

}

When I run the code, the data loads but when I modify the data and click save, I get a casting exception:

Unable to cast object of type 'System.Web.UI.WebControls.SqlDataSource' to type 'bcp_BusinessProcessDataTable'.

Is it possible to obtain a Visual Studio 2005, C# databind solution using SQL Server 2005 that can not only load data, but also save it? Providing an example, using the most common development stack, would help all programmers get off to a good start with Aspose.Grid.Web

Thanks,

Curtis

Hi,

Sure, the binding mode in vs 2005 is quite different than in vs 2002/2003. And we are working at improving the binding feature in vs 2005.

If you use the SqlDataSource control to bind the grid, you should realize that the DataSource property of the worksheet is a SqlDataSource object. But the WebWorksheet.BindingSource property is still a DataView object. So you can use this property to undate the database with a tableadapter.

for example:

protected void GridWeb1_SubmitCommand(object sender, EventArgs e)
{
DataSet1TableAdapters.employeeTableAdapter adapter = new DataSet1TableAdapters.employeeTableAdapter();
DataTable empTable = ((DataView)GridWeb1.WebWorksheets[0].BindingSource).Table;
DataRow[] rows = new DataRow[empTable.Rows.Count];
empTable.Rows.CopyTo(rows, 0);
adapter.Update(rows);
}

And the attachment is a vs 2005 demoproject, works with the SqlServer(SQLEXPRESS, pubs database).

Thank you for considering Aspose.

Thanks for the code. I used it and was able to get the web grid update working with Visual Studio 2005 using SQL Server 2005. When you get the improved binding feature in Visual Studio 2005 released, please post to the forum.

Curtis