Thursday, June 4, 2009

Standard code for Getting Data- VB.Net- Raides

Public Function GetData(Optional ByVal Filter As String = "") As DataSet
Try
Me.OpenConnection()
Dim TableParts() As String = Nothing
If Regex.IsMatch(Table, "\w+(?:\.\w+)+", RegexOptions.Singleline) Then
TableParts = Table.Split(".")
Else
ReDim TableParts(0)
TableParts(0) = Table
End If
Dim sqlstr As String = "SELECT * FROM "
For i As Integer = 0 To TableParts.Length - 1
sqlstr &= "[" & TableParts(i) & "]."
Next
sqlstr = sqlstr.TrimEnd(".") & IIf(Filter <> "", " WHERE " & Filter, "")
Dim ds As New DataSet
Dim cmd As New SqlCommand(sqlstr, Me.connection)
Dim Da As New SqlDataAdapter(cmd)
Da.Fill(ds, Table)
Return ds
Catch ex As Exception
'Throw New Exception(ex.Message)
Return Nothing
Finally
Me.CloseConnection()
End Try
End Function

Wednesday, May 13, 2009

Cell Validating in Datagridview

Private Sub UcdgvAuxiliary_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles UcdgvAuxiliary.CellValidating
If UcdgvAuxiliary.Columns(UcdgvAuxiliary.CurrentCell.ColumnIndex).Name = "StartDate" AndAlso UcdgvAuxiliary.CurrentCell.IsInEditMode = True Then
If Not UcdgvAuxiliary.EditingControl Is Nothing Then
If Not UcdgvAuxiliary.EditingControl.Text = "" Then
Dim ss As String = System.Text.RegularExpressions.Regex.Replace(UcdgvAuxiliary.EditingControl.Text, "^(((0[1-9][12]\d3[01])\/(0[13578]1[02])\/((1[6-9][2-9]\d)\d{2}))((0[1-9][12]\d30)\/(0[13456789]1[012])\/((1[6-9][2-9]\d)\d{2}))((0[1-9]1\d2[0-8])\/02\/((1[6-9][2-9]\d)\d{2}))(29\/02\/((1[6-9][2-9]\d)(0[48][2468][048][13579][26])((16[2468][048][3579][26])00))))$", "")
UcdgvAuxiliary.CurrentCell.Value = ss
UcdgvAuxiliary.EndEdit()
End If
End If
End If
End Sub

Tuesday, May 5, 2009

To commit the cahnges in DataGridView

to commit the cahnges in DataGridView


UcdgvAuxiliary.BeginEdit(True)


UcdgvAuxiliary.EndEdit(CType(True, DataGridViewDataErrorContexts))
UcdgvAuxiliary.CommitEdit(DataGridViewDataErrorContexts.Commit)

to commit the cahnges in DataGridView and DataBindings

to commit the cahnges in DataGridView

UcdgvAuxiliary.BeginEdit(True)

UcdgvAuxiliary.EndEdit(CType(True, DataGridViewDataErrorContexts))
UcdgvAuxiliary.CommitEdit(DataGridViewDataErrorContexts.Commit)

=================================================

ucbtnAuxiliary.BindingContext(dsAuxilKeys, dsAuxilKeys.Tables(0).TableName).EndCurrentEdit()
ucbtnsConcept.BindingContext(dsAuxilKeys, dsAuxilKeys.Tables(0).TableName).EndCurrentEdit()

Sql Server material downloads

Hi
Here these are Sql Server Marerial download links
http://www.ziddu.com/download/4552118/MsSQLServer2000.rar.html
http://www.ziddu.com/download/4351815/SQLServer2005_SSMSEE.rar.html
http://www.ziddu.com/download/4277299/DatabaseSQLServer.rar.html
http://www.ziddu.com/download/4277299/DatabaseSQLServer.rar.html
http://www.ziddu.com/download/4235316/AdministratorsGuideToMicrosoftSQLServer20052006.rar.html
http://www.ziddu.com/download/4235316/AdministratorsGuideToMicrosoftSQLServer20052006.rar.html

Monday, April 13, 2009

Regarding joins in sql server

can visit http://blog.sqlauthority.com/
INNER JOIN
This join returns rows when there is at least one match in both the tables.
OUTER JOIN
There are three different Outer Join methods.
LEFT OUTER JOINThis join returns all the rows from the left table in conjunction with the matching rows from the right table. If there are no columns matching in the right table, it returns NULL values.
RIGHT OUTER JOINThis join returns all the rows from the right table in conjunction with the matching rows from the left table. If there are no columns matching in the left table, it returns NULL values.
FULL OUTER JOINThis join combines left outer join and right after join. It returns row from either table when the conditions are met and returns null value when there is no match.
CROSS JOIN
This join is a Cartesian join that does not necessitate any condition to join. The resultset contains records that are multiplication of record number from both the tables.
Additional Notes related to JOIN:
The following are three classic examples to display where Outer Join is useful. You will notice several instances where developers write query as given below.
SELECT t1.*FROM Table1 t1WHERE t1.ID NOT IN (SELECT t2.ID FROM Table2 t2)GO
The query demonstrated above can be easily replaced by Outer Join. Indeed, replacing it by Outer Join is the best practice. The query that gives same result as above is displayed here using Outer Join and WHERE clause in join.
/* LEFT JOIN - WHERE NULL */SELECT t1.*,t2.*FROM Table1 t1LEFT JOIN Table2 t2 ON t1.ID = t2.IDWHERE t2.ID IS NULL
The above example can also be created using Right Outer Join.
NOT INNER JOINRemember, the term Not Inner Join does not exist in database terminology. However, when full Outer Join is used along with WHERE condition, as explained in the above two examples, it will give you exclusive result to Inner Join. This join will give all the results that were not present in Inner Join.
You can download the complete SQL Script here, but for the sake of complicity I am including the same script here.
USE AdventureWorksGOCREATE TABLE table1(ID INT, Value VARCHAR(10))INSERT INTO Table1 (ID, Value)SELECT 1,‘First’UNION ALLSELECT 2,‘Second’UNION ALLSELECT 3,‘Third’UNION ALLSELECT 4,‘Fourth’UNION ALLSELECT 5,‘Fifth’GOCREATE TABLE table2(ID INT, Value VARCHAR(10))INSERT INTO Table2 (ID, Value)SELECT 1,‘First’UNION ALLSELECT 2,‘Second’UNION ALLSELECT 3,‘Third’UNION ALLSELECT 6,‘Sixth’UNION ALLSELECT 7,‘Seventh’UNION ALLSELECT 8,‘Eighth’