Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
70
Send Data from WebGrid or UltraWebGrid to DB SQL Server 2005
posted

Dear All:

 Please can anybody help me to write a easy code to send changes of webgrid or ultrawebgrid to Sql Server 2005 Express ???

 i wrote the follwoing code but nothing changes ?!!

Imports System.Data

Partial Class _Default

Inherits System.Web.UI.Page

Private dataConnection As New SqlClient.SqlConnection("Data Source=BASHEER-PC\SQLEXPRESS;Initial Catalog=Equipments;Integrated Security=True")

Private c_dataAdapter As New SqlClient.SqlDataAdapter

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

c_dataAdapter = New SqlClient.SqlDataAdapter("SELECT Project_ID,Project_Name,Region FROM Projects", dataConnection)

' create insert, delete and update commands

Dim dataCommandBuilder As New SqlClient.SqlCommandBuilder(c_dataAdapter)

c_dataAdapter.InsertCommand = dataCommandBuilder.GetInsertCommand

c_dataAdapter.DeleteCommand = dataCommandBuilder.GetDeleteCommand

c_dataAdapter.UpdateCommand = dataCommandBuilder.GetUpdateCommand

' create temporary datatable

Dim tempDataTable As New DataTable("Projects")

c_dataAdapter.Fill(tempDataTable)

' bind datatable to UltraGrid

UltraWebGrid1.DataSource = tempDataTable

 

UltraWebGrid1.DataBind()

End Sub

 

 

Protected Sub Save_Data()

' get reference to grid datasource

Dim gridDataTable As DataTable = UltraWebGrid1.DataSource

' test for valid grid datasource

If gridDataTable Is Nothing Then Exit Sub

' send changes to database

c_dataAdapter.InsertCommand.Connection = dataConnection

c_dataAdapter.DeleteCommand.Connection = dataConnection

c_dataAdapter.UpdateCommand.Connection = dataConnection

 

c_dataAdapter.Update(gridDataTable)

End Sub

 

 

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Call Save_Data()

End Sub

End Class

 

this code worked very good in windows forms but not worked in ASP.NET 3.5 and no error apeared just without saving data to database.

 

Please help me. >>>

 

Best Regards

 

Basheer Massarrani

Civil & Electro Mechanical

KSA-Jeddah