hi guys,
following is the coding where i got error. when i update the modified rows in a datagrid the it shows error
"The timeout period elapsed prior to completion of the operation or the server is not responding"
please help me out i have treied a lot but got no success
Private Sub UpdateAvailRecord_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
sqlcon.Open()
Adapt.SelectCommand = Cmd
Cmd.Connection = sqlcon
Cmd.CommandText = "Select * from targetpath with (NOLOCK)"
Cmd.CommandType = CommandType.Text
Adapt.TableMappings.Add("TablePath", "TabPath")
Adapt.Fill(DtSet, "TabPath")
Cmd.Cancel()
If TelNumber.Length > 0 And Email.Length > 0 Then
If Old = 0 Then
Cmd.CommandText = "select candidateid,resumecode,name,contactnumber,Email,ex perience,skills,category,Location,lastactivitydate bycandidate,resumetext,updatedon from candidatedetails with (NOLOCK) where contactnumber like '%" & TelNumber.Trim.Replace("'", "''").ToString & "%' or email like '%" & Email.Trim.Replace("'", "''").ToString & "%'"
Else
Cmd.CommandText = "select candidateid,resumecode,name,contactnumber,Email,ex perience,skills,category,Location,lastactivitydate bycandidate,resumetext,updatedon from candidatedetailsold with (NOLOCK) where contactnumber like '%" & TelNumber.Trim.Replace("'", "''").ToString & "%' or email like '%" & Email.Trim.Replace("'", "''").ToString & "%'"
End If
ElseIf TelNumber.Length > 0 And Email.Trim.Length = 0 Then
If Old = 0 Then
Cmd.CommandText = "select candidateid,resumecode,Name,contactnumber,Email,ex perience,skills,category,Location,lastactivitydate bycandidate,resumetext,updatedon from candidatedetails with (NOLOCK) where contactnumber like '%" & TelNumber.Trim.Replace("'", "''").ToString & "%'"
Else
Cmd.CommandText = "select candidateid,resumecode,Name,contactnumber,Email,ex perience,skills,category,Location,lastactivitydate bycandidate,resumetext,updatedon from candidatedetailsold with (NOLOCK) where contactnumber like '%" & TelNumber.Trim.Replace("'", "''").ToString & "%'"
End If
ElseIf TelNumber.Length = 0 And Email.Trim.Length > 0 Then
If Old = 0 Then
Cmd.CommandText = "select candidateid,resumecode,name,contactnumber,Email,ex perience,skills,category,Location,lastactivitydate bycandidate,resumetext,updatedon from candidatedetails with (NOLOCK) where email like '%" & Email.Trim.Replace("'", "''").ToString & "%'"
Else
Cmd.CommandText = "select candidateid,resumecode,name,contactnumber,Email,ex perience,skills,category,Location,lastactivitydate bycandidate,resumetext,updatedon from candidatedetailsold with (NOLOCK) where email like '%" & Email.Trim.Replace("'", "''").ToString & "%'"
End If
End If
'Query = Cmd.CommandText
Cmd.CommandType = CommandType.Text
Adapt.TableMappings.Add("Table", "UpdateRec")
Adapt.Fill(DtSet, "UpdateRec")
Cmd.Cancel()
sqlcon.Close()
DataGrid.SetDataBinding(DtSet, "UpdateRec")
Dim DgTabStyle As New DataGridTableStyle
DgTabStyle.MappingName = "UpdateRec"
Dim DgTxtCol As New DataGridTextBoxColumn
DgTxtCol.MappingName = "ResumeCode"
DgTxtCol.HeaderText = "Resume Code"
DgTxtCol.ReadOnly = True
DgTabStyle.GridColumnStyles.Add(DgTxtCol)
DgTxtCol = New DataGridTextBoxColumn
DgTxtCol.MappingName = "Name"
DgTxtCol.HeaderText = "Name"
DgTxtCol.ReadOnly = True
DgTabStyle.GridColumnStyles.Add(DgTxtCol)
DgTxtCol = New DataGridTextBoxColumn
DgTxtCol.MappingName = "Contactnumber"
DgTxtCol.HeaderText = "Contact Number"
DgTabStyle.GridColumnStyles.Add(DgTxtCol)
DgTxtCol = New DataGridTextBoxColumn
DgTxtCol.MappingName = "Email"
DgTxtCol.HeaderText = "Email-Id"
DgTabStyle.GridColumnStyles.Add(DgTxtCol)
DgTxtCol = New DataGridTextBoxColumn
DgTxtCol.MappingName = "Experience"
DgTxtCol.HeaderText = "Experience"
DgTabStyle.GridColumnStyles.Add(DgTxtCol)
DgTxtCol = New DataGridTextBoxColumn
DgTxtCol.MappingName = "Skills"
DgTxtCol.HeaderText = "Skills"
DgTabStyle.GridColumnStyles.Add(DgTxtCol)
DgTxtCol = New DataGridTextBoxColumn
DgTxtCol.MappingName = "Category"
DgTxtCol.HeaderText = "Category"
DgTabStyle.GridColumnStyles.Add(DgTxtCol)
DgTxtCol = New DataGridTextBoxColumn
DgTxtCol.MappingName = "Location"
DgTxtCol.HeaderText = "Location"
DgTabStyle.GridColumnStyles.Add(DgTxtCol)
DgTxtCol = New DataGridTextBoxColumn
DgTxtCol.MappingName = "LastActivitydatebycandidate"
DgTxtCol.HeaderText = "Access Date"
DgTabStyle.GridColumnStyles.Add(DgTxtCol)
DgTxtCol = New DataGridTextBoxColumn
DgTxtCol.MappingName = "Resumetext"
DgTxtCol.HeaderText = "Resume"
DgTabStyle.GridColumnStyles.Add(DgTxtCol)
DgTxtCol = New DataGridTextBoxColumn
DgTxtCol.MappingName = "updatedon"
DgTxtCol.HeaderText = "Last Updated"
DgTabStyle.GridColumnStyles.Add(DgTxtCol)
DataGrid.TableStyles.Add(DgTabStyle)
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
End Sub
Private Sub UpdateAvailRecord_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
DtSet.Clear()
DtSet = Nothing
Adapt.Dispose()
Me.Dispose()
End Sub
Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click
If DtSet.HasChanges(DataRowState.Modified) Then
Try
If TxtExcelFile.Text.Length > 0 Then
If Old = 0 Then
File.Copy(TxtExcelFile.Text.Trim.ToString, DtSet.Tables("TabPath").Rows(0).Item("Path").ToStr ing & "\" & TxtExcelFile.Text.Trim.Substring(TxtExcelFile.Text .LastIndexOf("\") + 1), True)
Else
File.Copy(TxtExcelFile.Text.Trim.ToString, DtSet.Tables("TabPath").Rows(0).Item("Path").ToStr ing.Substring(0, InStrRev(DtSet.Tables("TabPath").Rows(0).Item("Pat h").ToString, "\", , CompareMethod.Text) - 1) & "\uploadold\" & TxtExcelFile.Text.Trim.Substring(TxtExcelFile.Text .LastIndexOf("\") + 1), True)
End If
Else
MessageBox.Show("Please Choose The New Resume File", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End If
'Dim Adpt As New SqlDataAdapter(Query, ConStr)
'Adpt.TableMappings.Add("Table", "UpdateRec")
Dim CmdBuild As SqlCommandBuilder = New SqlCommandBuilder(Adapt)
'Adpt.UpdateCommand = CmdBuild.GetUpdateCommand
Adapt.UpdateCommand = CmdBuild.GetUpdateCommand
'Dim DSet As DataSet
'DSet = DtSet.GetChanges(DataRowState.Modified)
'Call Adpt.Update(DSet)
Adapt.Update(DtSet.Tables("UpdateRec").GetChanges( DataRowState.Modified))
DtSet.AcceptChanges()
MsgBox("Database Updated")
TxtExcelFile.Text = ""
Me.Dispose()
Catch Ex As Exception
MsgBox(Ex.ToString)
End Try
End If
End Sub
|