Monday, September 22, 2014
Tuesday, August 19, 2014
VB.NET Datagridview sort a column
- DGV.Sort(DGV.Columns("datum"), System.ComponentModel.ListSortDirection.Ascending)
Thursday, August 14, 2014
best way to do connection and GetData
Public Shared Function GetData(Query As String) As DataTable
Try
Dim connString As String = WebConfigurationManager.ConnectionStrings("myConnectionString").ToString
Using con As New SqlConnection(connString)
Using cmd As New SqlCommand()
cmd.CommandText = Query
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using ds As New DataSet()
Dim dt As New DataTable()
sda.Fill(dt)
Return dt
End Using
End Using
End Using
End Using
Catch ex As Exception
Return Nothing
End Try
End Function
Try
Dim connString As String = WebConfigurationManager.ConnectionStrings("myConnectionString").ToString
Using con As New SqlConnection(connString)
Using cmd As New SqlCommand()
cmd.CommandText = Query
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using ds As New DataSet()
Dim dt As New DataTable()
sda.Fill(dt)
Return dt
End Using
End Using
End Using
End Using
Catch ex As Exception
Return Nothing
End Try
End Function
Tuesday, August 12, 2014
Code! MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on (C#)
Link 1
http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on
Link 2
http://aspsnippets.com/Articles/Login-with-FaceBook-account-in-ASPNet-Website.aspx
Link 3
http://www.theroks.com/social-login-owin-authentication-mvc5/
some solutions
in the facebook App Page, goto the basic tab. find "Website with Facebook Login" Option.
you will find Site URL: input there put the full URL ( for example http://Mywebsite.com/MyLogin.aspx ). this is the URL you can use with the call like If the APP ID is 123456789
https://graph.facebook.com/oauth/authorize?client_id=123456789&redirect_uri=http://Mywebsite/MyLogin.aspx&scope=publish_actions
http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on
Link 2
http://aspsnippets.com/Articles/Login-with-FaceBook-account-in-ASPNet-Website.aspx
Link 3
http://www.theroks.com/social-login-owin-authentication-mvc5/
some solutions
in the facebook App Page, goto the basic tab. find "Website with Facebook Login" Option.
you will find Site URL: input there put the full URL ( for example http://Mywebsite.com/MyLogin.aspx ). this is the URL you can use with the call like If the APP ID is 123456789
https://graph.facebook.com/oauth/authorize?client_id=123456789&redirect_uri=http://Mywebsite/MyLogin.aspx&scope=publish_actions
Monday, August 11, 2014
Operation not Allowed error for files over 200kb in IIS. Error: 80004005
Operation not Allowed error for files over 200kb in IIS
Document ID: 2711HQ
Issue:
An 'Operation not Allowed' error occurs when Eudora Web Client is installed on IIS while trying to attach files over 200k. The error commonly associated with this problem is:
Request object error 'ASP 0104 : 80004005'
Operation not Allowed
<system.webServer>
<defaultDocument>
<files>
<add value="publish.htm" />
</files>
</defaultDocument>
<asp scriptErrorSentToBrowser="true">
<limits maxRequestEntityAllowed="10485760" />
</asp>
<staticContent>
<mimeMap fileExtension=".appcache" mimeType="text/cache-manifest" />
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
</staticContent>
<httpErrors errorMode="Detailed" />
</system.webServer>
Document ID: 2711HQ
Issue:
An 'Operation not Allowed' error occurs when Eudora Web Client is installed on IIS while trying to attach files over 200k. The error commonly associated with this problem is:
Request object error 'ASP 0104 : 80004005'
Operation not Allowed
Solutions
<system.webServer>
<defaultDocument>
<files>
<add value="publish.htm" />
</files>
</defaultDocument>
<asp scriptErrorSentToBrowser="true">
<limits maxRequestEntityAllowed="10485760" />
</asp>
<staticContent>
<mimeMap fileExtension=".appcache" mimeType="text/cache-manifest" />
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
</staticContent>
<httpErrors errorMode="Detailed" />
</system.webServer>
Sunday, August 10, 2014
VB.NET DataGridView
DataGridView provides a visual interface to data. It is an excellent way to display and allow editing for your data. It is accessed with VB.NET code. Data edited in the DataGridView can then be persisted in the database.
Example
First, you should add a DataGridView control to your Windows Forms application by double-clicking on the control name in the Visual Studio designer panel. After you add the control, you can add the Load event on the form.
Load:You can create the Load event on the Form's event pane in Visual Studio. We use Load in this example.
Here:We use an empty DataTable on the DataGridView control.
We assign the DataSource property.
We assign the DataSource property.
Program that uses DataGridView: VB.NET
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'
' Fill in the data grid on form load.
'
DataGridView1.DataSource = GetDataTable()
End Sub
Private Function GetDataTable() As DataTable
'
' This Function needs to build the data table.
'
Return New DataTable()
End Function
End Class
This event handler is executed when the program starts up and when the DataGridView control is displayed. The Form1_Load sub calls into the GetDataTable function, which would return a DataTable from your database in SQL Server.
Assigning the DataSource property on DataGridView copies no data. It allows the DataGridView to read in the DataTable and display all its contents on the screen in grid form. This is an efficient way to populate DataGridView.
DataTableLightning bolt
When using the DataGridView control in Windows Forms, you should use the lightning bolt panel. This allows you to manipulate the events on the control. DataGridView has many events, and this article doesn't describe them all.
However:You will often want the CellClick, SelectionChanged, CellDoubleClick, and KeyPress events, depending on your requirements.
Objects
You can use an object collection, such as a List(Of String), in your DataGridView using the Visual Basic language. The object collection will be read. Its properties (get accessors) will be used to display the values on the screen.
List
Tip:This is the easiest way to get started with DataGridView. But it may be less effective than more complex approaches.
Class used in program: VB.NET ''' <summary> ''' This class contains two properties. ''' </summary> Public Class Test Public Sub New(ByVal name As String, ByVal cost As String) _name = name _cost = cost End Sub Private _name As String Public Property Name() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property Private _cost As String Public Property Cost() As String Get Return _cost End Get Set(ByVal value As String) _cost = value End Set End Property End Class Program that uses DataGridView with class: VB.NET Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load ' ' Fill in the data grid with a List ' Dim list = New List(Of Test) list.Add(New Test("Mac", 2200)) list.Add(New Test("PC", 1100)) DataGridView1.DataSource = list End Sub End Class
The program includes the Public Class Test definition, which encapsulates two properties with backing stores. The names of these properties are Name and Cost. These could be used for an inventory of merchandise.
Note:It is important to declare the members as properties so the metadata can be used by the DataGridView.
After the Dim List is allocated, two new Test objects are added to its contents. These two objects are reflected in the DataGridView output to the screen. You can see the four cells from the four values in the example in the screenshot.
Hide row headers
You can hide the row headers, which are the boxes on the left of the DataGridView control, from appearing on the screen. The screenshot shows what the row headers look like on DataGridView controls.
Tip:Go to the Visual Studio designer and change the value of RowHeadersVisible to false. This hides row headers.
Improve tabbing
It is possible to improve the behavior for tabbing into and out of the DataGridView control in your Windows Forms program. You can change the StandardTab property on the control in the Visual Studio designer.
So:When StandardTab is enabled, the focus will move out of the DataGridView control when the user presses tab.
Add rows
We can manually add rows to the DataGridView control. The Rows.Add function will return the index of the newly-added row. After calling Rows.Add, you can use the Item accessor and the column index to assign the Value properly.
Here:The example adds a row with two strings to the DataGridView on load. These are displayed to the screen.
Program that adds rows: VB.NET
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Add row using the Add subroutine.
Dim n As Integer = DataGridView1.Rows.Add()
DataGridView1.Rows.Item(n).Cells(0).Value = "First"
DataGridView1.Rows.Item(n).Cells(1).Value = "Second"
End Sub
End Class
Adding columns in designer first. The example throws an exception if you do not have at least two columns in the DataGridView. To add columns to the control, you can use the Columns collection in the designer and use the Add button.
Then:After you add the columns, compile and run your program and no exception will be thrown.
Edit ColumnsGet current cell
We can obtain the location of the current cell in VB.NET code. One way you can do this is add the SelectionChanged event. As a reminder, you can add events easily in Visual Studio by using the lightning bolt panel.
Next, in the DataGridView1_SelectionChanged event, you can access the DataGridView1.CurrentCellAddress property. This is a System.Drawing.Point type that has two instance properties, X and Y.
Tip:You can use the Point itself or just access its properties. Its properties are of type Integer.
Program that gets current cell: VB.NET
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Uses Test class from above.
Dim list = New List(Of Test)
list.Add(New Test("Mac", 2200))
list.Add(New Test("PC", 1100))
DataGridView1.DataSource = list
End Sub
Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DataGridView1.SelectionChanged
' Get the current cell location.
Dim y As Integer = DataGridView1.CurrentCellAddress.Y
Dim x As Integer = DataGridView1.CurrentCellAddress.X
' Write coordinates to console.
Console.WriteLine(y.ToString + " " + x.ToString)
End Sub
End Class
The example shows the SelectionChanged event handler. SelectionChanged signals when the user changes the current cell or clicks on any cell. It is ideal to use for accessing the cell address and changing the UI based on some criteria.
Expand cells
It is possible to make the cells in a DataGridView expand horizontally. You can set the AutoSizeColumnsMode to fill. Also, you can weight certain columns to have larger widths than other columns using the Edit Columns dialog box.
Double-clicking
You can handle the events that occur when the user double-clicks on a cell. You can open the Visual Studio designer and add the CellDoubleClick event in the pane with the lightning bolt.
Note:When the CellDoubleClick event occurs and the header was clicked on, the RowIndex of the DataGridViewCellEventArgs parameter is -1.
Program that uses double-clicking: VB.NET
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Load here.
End Sub
Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles DataGridView1.CellDoubleClick
If e.RowIndex = -1 Then
Return
End If
' Double-click logic.
End Sub
End Class
Summary
We looked at the DataGridView control in the VB.NET language targeting the .NET Framework. This control is ideal for rendering data to the screen in programs that use collections of objects or databases and DataTable instances.
And:We used the DataSource property, looked at events, tabbing, row headers, and cells in the DataGridView control.
How to able HTML5 cach application in IIS
<configuration>
<system.web>
<compilation explicit="true" strict="false" targetFramework="4.0" />
<identity impersonate="true" password="password" userName="username" />
</system.web>
<system.web>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<defaultDocument>
<files>
<add value="publish.htm" />
</files>
</defaultDocument>
<asp scriptErrorSentToBrowser="true" />
<staticContent>
<mimeMap fileExtension=".appcache" mimeType="text/cache-manifest" />
</staticContent>
<httpErrors errorMode="Detailed" />
</system.webServer>
<location path="OfflineApp.appcache">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>
<system.web>
<compilation explicit="true" strict="false" targetFramework="4.0" />
<identity impersonate="true" password="password" userName="username" />
</system.web>
<system.web>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<defaultDocument>
<files>
<add value="publish.htm" />
</files>
</defaultDocument>
<asp scriptErrorSentToBrowser="true" />
<staticContent>
<mimeMap fileExtension=".appcache" mimeType="text/cache-manifest" />
</staticContent>
<httpErrors errorMode="Detailed" />
</system.webServer>
<location path="OfflineApp.appcache">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>
How do I discover the user's Desktop folder?
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
How to get the source code of a html page using VB.net?
Dim sourceString As String = New System.Net.WebClient().DownloadString("SomeWebPage")
How to convert Excel column numbers into alphabetical characters
Function ConvertToLetter(iCol As Integer) As String
Dim iAlpha As Integer
Dim iRemainder As Integer
iAlpha = Int(iCol / 27)
iRemainder = iCol - (iAlpha * 26)
If iAlpha > 0 Then
ConvertToLetter = Chr(iAlpha + 64)
End If
If iRemainder > 0 Then
ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
End If
End Function
Dim iAlpha As Integer
Dim iRemainder As Integer
iAlpha = Int(iCol / 27)
iRemainder = iCol - (iAlpha * 26)
If iAlpha > 0 Then
ConvertToLetter = Chr(iAlpha + 64)
End If
If iRemainder > 0 Then
ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
End If
End Function
how to check the application is already running using vb.net..?
Just enable the "Make single-instance application" checkbox in your application properties.
Subscribe to:
Posts (Atom)
