Monday, August 31, 2009

CRUD operations with LINQ To SQL(ASP.NET 3.5)





Hi Readers,

Thank you for you emails.I appreciate it.
Here are some tips if you want to use LINK To SQL to select, insert,
delete and update known by CRUD.
I used ASP.NET AJAX web Template for this demo and VS 2008
Here are steps:

1-Add a new table called Users to Northwind database :

CREATE TABLE
[dbo].[Users](
[UserID] [int] IDENTITY(1,1) NOT NULL,
[UserName] [nvarchar](50) NOT NULL,
[Password] [nvarchar](50) NOT NULL,
[Email] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[UserID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]



2-Create ASP.NET AJAX web app and make sure ScriptMaster is in place(without it
ajax functionality=null).Make also sure that Ajax ToolKit controls are in place.
Drop Tab Container on the design surface with 4 tabs:
-Query Task tab: to query and show result on GridView control
-Insert Task tab : to insert new records .
-Update Task tab: to update records
-Delete Task tab: to delete record.



Copy the source code Demo.Zip



Here is how it works:



A-For Query Task:



The goal of this task is to load data into GridView control via a button control:



' This code will query all users where UserName is not null

Dim users=From usr In db.Users _

Where usr.UserName IsNot Nothing _

Select usr

'This code bind users data to GridView control



Me.GridView1.DataSource=users

Me.GridView1.DataBind()



B-For Insert Task:



'I defined a new User class and i used the column names

'you need With which allows you select column names

'after you type .(dot) inside {} column names will appear automatically



Dim u as New User With {.UserName=me.txtUserName,.PassWord=me.txtPassWord,.Email=me.txtEmail}



'Now submit result on Insert and Update table

db.Users.InsertOnSubmit(u)

db.SubmitChanges()



C-For Update Task:



'This section is little loosy

'I select users where UserID=upUserID.txt

'You need these parentheses to make it work

'You need to specifiy single meaning you are

'updating only a single row

'match columns again fields

'finally update user table



Dim u=(From usr In db.Users _

Where usr.UserID=me.upUserID.txt _

Select usr).Single

u.UserName=me.upUserName.text

u.PassWord=me.upPassWord.text

u.Email=me.upEmail.text



db.SubmitOnChanges()



D-Delete Task:



'Tricky too

Dim p1=db.Users.First(Function(p) p.UserID=me.delUserID.text

db.Users.DeleteOnSubmit(p1)

db.SubmitChanges()



Run app and if everything is ok you should see something like this:























Friday, August 28, 2009

Do you know the Best developers IDE?

Hi readers,
Thank you for your emails.I received 80 emails yesterday.
I appreciate it.

Here is the top 4 IDE for both .Net and Java Developers:

No1 Visual Studio 2008(Pro and Team Editions) from Microsoft.com
Why No1? Because all is visual (windows& web apps) and it has robust
framework behind it.

No2 Netbeans IDE from Netbeans.org(Java,C++,Ruby,PHP,Python..)
It has all except the visual part is missing except Swing(Java)

No3 Eclipse IDE(Java) from eclipse.org

No4 Aptana Studio (Java,PHP,Ruby,Perl) from aptana.com

There are still good IDE out there but these are the top one.

Thank you for reading.

Talley Ouro
johnstalley@live.com

Do you know which version of AJAX Toolkit to use for VS2005?

Hi readers,
Thank you for your emails.I appreciate it.

If you have Visual Studio 2005 and wonder which version of Ajax ToolKit
to use then i have the answer.
The version to use is 20229

You can download it directly on my downlaod page HERE
If you are having problem clik HERE

That`s all i want to share with you today.

Thank you for visiting my blog!

Talley Ouro
johnstalley@live.com
Raleigh,NC.

Sunday, August 23, 2009


XScheduler will be release end September 2009 easten time.

XScheduler is an Advanced Document Management System,

Business Process System,Employee Task Management,Active

Directory Manager,Government Ressource Planning(GRP)

and more to come.

I published some screenshots from the program but these

screenshots are 1/200 of the screeshots and will be update

every friday.Thank you for reading and see you soon!


Talley Ouro,

Project Manager and Administrator

Cary,NC USA

How to get the current Primary Key from GridView(ASP.NET 2.0/3.5)?

Hi Readers,

Thank you for your emails .I am very grateful to your emails.They help me
post more blogs even i am very busy debug codes.

Take a good look at this grid:



What if i want to update Documents table with this statement:

Update Documents SET Status='Active' WHERE DocumentID=Current selected row on gridview!!!!(Remember Document is a SQL Keyword)

Here are the easy way to do it(VB.NET):

Step1: fire RowCommand event from Gridview( ex GridView1_RowCommand ...Handles GridView1.RowCommand)

Step2: Use CommandName and CommandArgument properties

Ex commandname are :Edit,Update,Delete,Insert....
commandargument is used to find the primary key of currently select item on gridview

Here is the code within GridView1_RowCommand :

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand

Dim itm As Integer
If e.CommandName.Equals("Edit") Then

itm = Convert.ToInt32(e.CommandArgument) REM get primary key of selected row on gridview
UpdateStatus(itm)
REM your code goes here.Update() is a function with parameter named itm.
It goals is to update Documents table based on selected row on the grid.

End If

End Sub


That`s all i want to share with you today.
Any question or if you want private training a lower cost please send
me email at johnstalley@live.com

Thanks
Talley Ouro
.Net Developer(VB.NET,C#,PHP,ASP.NET 2.0/3.5)

Saturday, August 22, 2009

New To LINQ To SQL?Watch this video

Introduction to Windows Live Cloud Services

Hi readers,





All IT compagnies are moving from traditional computer systems into cloud computing.


The good news is Microsoft invested a lot into it.


As a programmer and a member of MSDN network i invested myself into this too.


I am working on a Business Process/Workflow program which will be published soon on sourceforge.net and i need a chat control for the chart section of my project.I created a C# class library project which has all the functionality i needed for chat purposes.But i need something quick and fast.I have 1000 lines of code to review .So i checked Windows Live Services and i found a control that fit my need.


Here is a link to live service: link


To get started with Windows Live Controls(work both with VS 2005/2005) i precompile required bin on my download page .Copy Live Chat Bin here


Here are the steps:


Step1: Unzip Live Chat Bin and copy them into the bin section of your web project.





Step2: Open toolbox window from VS ,add a new tab and select choose items.Locate the ddl from step1 and click ok .You should see something like this:











Step 3:Drag any control from the list( i picked MessengerChat in my case).


NB :Remember to set PrivacyStatementUrl in order for MessengerChat to work properly.


The output shoud look like this after you run the browser:









Again thank you for you emails.

Talley Ouro
johnstalley@live.com
.Net Web & Windows Developer

Thursday, August 20, 2009

How to bind XML Data to GridView or DataGrid?

Hi Readers,

Thank you for reading my blog.I received 40 emails yesterday.

Here is how to bind xml data to GridView or DataGrid:

Download aspnetbooks.xml source code here

Step 1:

-Add reference to System.Data and System.XML
In VB.NET :
imports System.Data
imports System.Xml

In C# :
using System.Data;
using System.Xml;

Step2:
-Drop a GridView or DataGrid on designer surface
-Double click on designer for Page_Load event

Step3:Add this code inside Page_Load

In VB.NET :

Dim ds As New DataSet
Dim XMLMode As New System.Data.XmlReadMode
ds.ReadXml(GetXMLPath("Demos/aspnetbooks.xml"))
Me.GridView1.DataSource = ds
Me.GridView1.DataBind()

I programmed GetXMLPath function which is:

Protected Function GetXMLPath(ByVal xmlpath As String) As String
Return Request.PhysicalApplicationPath & xmlpath
End Function

In C#:

DataSet ds=new DataSet();
System.Data.XmlReadMode XMLMode=new System.Data.XmlReadMode();
ds.ReadXml(GetXMLPath("Demos/aspnetbooks.xml"))
this.GridView1.DataSource = ds
this.GridView1.DataBind()

for the function:

protected string GetXMLPath(string xmlpath)
{
return Request.PhysicalApplicationPath + xmlpath
}

Note + sign instead of & inside GetXMLPath method(C# uses + while VB.NET uses &)

The code inside VS should look like this:






The output should look like this:



Thank you for reading.

Any question or if you need private online training please email me at
johnstalley@live.com

Talley Ouro
Raleigh,NC

Free HTML control for your VS 2005/2008 Projects



Hi all,

Do you want this control in your VS(Visual Studio)2005/2008 projects?
If so please download the DLL and sample project i precompile for you.
Here is the link http://sites.google.com/site/developercodesclub/downloads

Steps:

1-Copy the DLL to the bin section of your project and refresh the project
2-Go to ToolBox and Rick Click on it and choose Add Tab ang give it a name.
3-Right Click on the newly name you gave on 2 and click on Choose Items.Locate
the HTML Editor dll on project bin(Winthusiasm.HtmlEditor.dll) and clickOK.
It should look like this :




4-Now drag it on designer surface and that is all.You can disable OK and Cancel Buttons on designer surface or from property window.



Pleas leave your comments on my blog.

Thanks you for visiting my blog.Keep coming for more blogs.

Talley Ouro
C#,VB.NET,ASP.NET,PHP,Java(use java for fun) Developer
Raleigh,NC

Monday, August 17, 2009

How to configure Visual Studio 2005/2008 to use Enterprise Library for Data Access?

Here is the quickest way to configure visual studio to use Enterprise Library.

System Requirements:

-Microsoft Visual Studio 2005/ 2008 development system (any of the following editions):
Standard Edition
Professional Edition
Team Edition for Software Developers
Team Edition for Software Testers
Team Edition for Software Architects
Team Suite

-For the Data Access Application Block, the following is also required:

A database server running a database that is supported by a .NET Framework 2.0/3.5 data provider. This includes SQL Server 2000 or later

-To run the Unit Tests, the following is also required:

Visual Studio 2008 Professional or Visual Studio 2008 Team Edition. Enterprise Library includes both unit test binaries and source code.

-For the Logging Application Block, the following is also required:
Stores to maintain log messages. If you are using the MsmqTraceListener trace listener to store log messages, you need a message queue. If you are using the DatabaseTraceListener trace listener to store log messages, you need a database server. If you are using the EmailTraceListener trace listener to store log messages, you need an SMTP server.

After these requirements you need to download Enterprise Library 4.0 - May 2008
(It working fine for both VS2005/2008).
Download it here

After you download it open both Visual Studio 2005/2008 and Enterprise Configuration Libary tool(C:\Program Files\Microsoft Enterprise Library May 2008\bin bleu icon)

-After you open the config tool you need add Data Access Block from it.You will see this image



-Right Click(RC) on Enterprise Library Configuration and choose New Application

-After that RC on Application Configuration and choose New then Data Access Application Block

-Change the connection Name and string that will match the connection string of your applicatio.
Database=Database;//name of your database

Server=(local)\SQLEXPRESS;Integrated Security=SSPI //name of your server




-Save it on the location of your application aroung web.config or app.config

-Open VS 2005/2008 ,RC on web.config and add these 3 configurations between configuration tags(You can get this by openning the saved configuration from the tool)






That`s all you need to get started with Enterprise Library Configuration .
You are ready to start Data Access Block.

Talley Ouro,
Developer Cary,NC,USA
johnstalley@live.com

Sunday, August 16, 2009

How to Enable Administrator Account on Vista

Here are the steps to enable Administrator Account on VISTA:

1-Right Click on CMD prompt and choose Run As Administrator

2-When command windows pops up type the following command and press ENTER

net user administrator /active:yes






That`s all you need.

NB To disable the account use net user administrator /active:no

You need to restart LogOut your pc in order to take effect.

Talley Ouro
johnstalley@live.com

Best VB.NET 2005/2008 Books

Hi,
If you want to become vb.net expert buy these books depending on what version of
.Net Plateform you are using.
You can buy them on bn.com.




SQL Server 2005 Authentication

How a add SQL Login to SQL Server

FIRST STEP

1-Login to SSMS with Windows Authentication

2-Click on Security/Login

3-RC Login/Add New Login

4-Enter name/Choose SQL Authentication/Enter strong password(8 characters min with
special key @#...) and click OK.






SECOND STEP: Assign grants

1-Login in again with Windows Auth

2-Click on Databases then choose the db on which you want to assign User

3-Go to security(inside the db) then Users

4-RC Users/Add New User

5-Click on Eclipse after Login name and select login will popup

6-Enter first 2 letters of the user you want to add and click on Check Name Button

7-Choose the name of the user you added on first step and click OK twice.

8-Copy the same name on step 7 and paste on the textbox after Username

9-Under Schemas owned by this user choose appropriate schemas especially db_datareader,
db_datawriter,db_datacessadmin,db_owner).You can add more later.

10-Database role membership choose roles for this user(Usually the same as 9) and click OK.





You done with SQL Authentication.
Start SSMS and login with the user and password you just created. Make sure you choose SQL Server Authentication.

Thursday, August 13, 2009

Solution to this error:Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)

Just turn off recursives triggers,views ,functions and store pro wich
cause the problem.
For trigger for example Go to SSMS,open the table in question,open trigger folder
and right click the trigger that cause the problem and choose disable.
You should be good to go.


Talley Ouro
Developer

Saturday, August 8, 2009

Useful JavaScripts for DataGrid control






This codes will help you with your datagrid activities.
You have to add a CheckBox to datagrid.

HTML Code


this html tag adds a checkbox to header 1-add asp:TemplateColumn tag
2-add HeaderTemplate tab
3-add input tag with id=checkAll,type=checbox,onclick=DGSelectOrUnselectAll('DataGrid1',this,'chkDel')

this html tag adds checkbox to datagrid 1-add ItemTemplate tag
2-add asp checkbox control within ItemTemplate tag with id=chkDel,RunAt=server


JavaScript codes:Add these js code in
section of HTML

this is to select or unselect the datagrid check boxes

function DGSelectOrUnselectAll(grdid,obj,objlist){
//this function decides whether to check or uncheck all
if(obj.checked)
DGSelectAll(grdid,objlist)
else
DGUnselectAll(grdid,objlist)
}
//----------

function DGSelectAll(grdid,objid){
//.this function is to check all the items
var chkbox;
var i=2;

chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);

while(chkbox!=null){
chkbox.checked=true;
i=i+1;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
}

}//--------------

function DGUnselectAll(grdid,objid){
//.this function is to uncheckcheck all the items
var chkbox;
var i=2;

chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);

while(chkbox!=null){
chkbox.checked=false;
i=i+1;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
}
}

If you have question please email me at johnstalley@live.com
My name is Talley Ouro,Developer in Raleigh,NC

Thursday, August 6, 2009

How to hack "Failed to query a list of database names from the SQL Server"

Sometimes ASP.NET Configuration Tool(ASP.NET) is a pain in the ass when trying to add aspnet.db for role management.

By default on Vista the current user on the machine is not a member of SysAdmin on SQL Server 2005/2008.

So here is the trick.

1-Open Sql Server Surface Area Configuration tool from C:\Program Files\Microsoft SQL Server 2005/2008.






2-When the screen pops up click on Add New Administrator.





-on top right make sure that User to provision=Username of the pc
-on your left (Available Privileges) select Member of SQL Server SysAdmin and click on the right arrow (>)
-click ok and you should be ready to go.

My name is Talley Ouro,Developer in Raleigh,NC
Blog: http://talleyblogs.blogspot.com/
Email:johnstalley@live.com

Sunday, August 2, 2009

Code to add JavaScript confirmation dialog to a button in a datagrid




Here is the code.It is free like "free beer".If you have question send me email at johnstalley@live.com.Remember datagrid index it 0 based.
NB You could add another parameter to the function that will execute when click=ok



public static void AddConfirm(DataGrid theGrid, int columnNumber, string question)
{
//for each row in the DataGrid
foreach(DataGridItem item in theGrid.Items)
{
//for each webcontrol in the column
foreach(WebControl control in item.Cells[columnNumber].Controls)
//if it is a LinkButton or Button
{
if(control is LinkButton || control is Button)
//add the attribute
control.Attributes.Add("OnClick", " javascript:return confirm('" + question + "');");
}
}
}

How to color a row of DataGrid in ASP.NET 2.0/3.5



1-Here is the code in VB.NET 2005/2008
The name i gave empGrid to the datagrid.To do this go the property of datagrid and
click on the events section and double click on ItemDataBound event and add the code.

Protected Sub empGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles empGrid.ItemDataBound

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim Status As String = Convert.ToString(drv.Row.Item("Status"))

If Status = "Active" Then
e.Item.Cells(4).BackColor = Drawing.Color.Green

ElseIf Status = "Inactive" Then
e.Item.Cells(4).BackColor = Drawing.Color.Red

End If
End If
End Sub
1-Here is the code in C# 2005/2008
The name i gave empGrid to the datagrid.To do this go the property of datagrid and
click on the events section and double click on ItemDataBound event and add the code.

private void empGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView Drv = (DataRowView)e.Item.DataItem;
// Get fourth column value.The coloumn needed
String Status = Convert.ToString(rv.Row.ItemArray[4]);
if (Status =="Active")
{
e.Item.Cells[4].BackColor = Color.Green;
}
//Just add the remaining steps
}
}

This code is free like "Free Coffee"

Talley Ouro

About Me

My photo
Raleigh, NC, United States
I am a software developer based in Raleigh,NC,USA.I design softwares and systems ;i also do consulting for companies worldwide.I program with these languages:VB.NET 2003/2005/2008;C#;Java(fun),SQL(200,2005,2008);ASP.NET 2.0/3.5;ASP.NET AJAX;ASP.NET MVC;JavaScript;JQuery;Windows Workflow Foundation;Web Services.I have 4 years + in programming.