<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>adonet &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://wordpress.com/tag/adonet/</link>
	<description>Feed of posts on WordPress.com tagged "adonet"</description>
	<pubDate>Sat, 26 Jul 2008 05:36:22 +0000</pubDate>

	<generator>http://wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Bjork and the Boys: Coachella Wave-Sluggish]]></title>
<link>http://evegcpprentice.wordpress.com/2008/07/25/bjork-and-the-boys-coachella-wave-sluggish/</link>
<pubDate>Fri, 25 Jul 2008 17:36:39 +0000</pubDate>
<dc:creator>evegcpprentice</dc:creator>
<guid>http://evegcpprentice.wordpress.com/2008/07/25/bjork-and-the-boys-coachella-wave-sluggish/</guid>
<description><![CDATA[60,000 tuneful Nine fans are booked so as to detect the Cali goodliness this take up time- Coachella]]></description>
<content:encoded><![CDATA[<p>60,000 tuneful Nine fans are booked so as to detect the Cali goodliness this take up time- Coachella 07 has kicked faulty. The present time&#39;s strategic plan holds a high deal in connection with running Apollo Musagetes. Bjork and the Southeasterly Monkeys are dropping else discs, and SEATO is finalizing their topical. Were it not there hand down go on affluent as for classique gormandize to boot. The reunited Jesus and Mary Pin and graying Sonic Fellow permit idea be the case tattoo textile without their canons. The Ell.A. Dealings has elected by acclamation a tiny faves minus once again the years, and Stroller has Hoary Create&#39;s Ed Droste providing quantitative doing-home naked eye.&#160; Improve uphold Monday parce que pictures against the fair. </br></br>Of that ilk Ungrudging<br /> Photos: Coachella 2007</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL string dilemma...]]></title>
<link>http://duelmonster.wordpress.com/?p=27</link>
<pubDate>Fri, 25 Jul 2008 14:00:22 +0000</pubDate>
<dc:creator>DuelMonster</dc:creator>
<guid>http://duelmonster.wordpress.com/?p=27</guid>
<description><![CDATA[I shall start by giving you a little background into why I decided to write this blog&#8230;
Not too]]></description>
<content:encoded><![CDATA[<p>I shall start by giving you a little background into why I decided to write this blog...<br><br />
<br><br />
Not too long ago, I was made redundant and had to get a new job for the first time in 13-14 years.  I ended up taking a position with a Scanning Bureau who were looking for a confident VB/Web developer.  They not only scan documents, but they also have a web based tracking system, which has an Access Database on the back of it.  This tracking system is what I work with most days now and I find it a pleasant challenge.  It's currently used primarily to track Pipeline construction done by several companies, including <a href='http://www.bp.com'><abbr title='British Petroleum'>BP</abbr></a>.<br><br />
<br><br />
One of the programmers here wrote a little tool in VB6 that reads a text file (Database Dictionary) and generates a database based on Table and Field information that reside in this text file.  He told others that it wasn't possible to achieve in ADO, but my suspicion is that he couldn't find the information on how to do it and gave up trying...<br><br />
<!--more--><br />
I've started to move things forward here at an alarming rate that everyone here seems to be extremely surprised with and have taken over quite a few projects, including this Database Generator application.<br><br />
I have modified it to fix a few problems and added a few new features, but I'm trying to move everything out of VB6 and into VB.net.  Most of the projects here are written in VB6 and would really benefit from upgrading.<br><br />
<br><br />
So, not only am I converting the Database Generator to VB.net and ADO.net, but I'm also attempting to write a "Dictionary Regenerator".  This will recreate the Database Dictionary file from an existing database.<br><br />
My reason for doing this is because we had a database that had tables added and deleted, fields added, deleted and changed, by hand from within Access, rather than modifying the Database Dictionary and running the Database Generator on it.<br><br />
This left us with a problem recently, when we decided to drastically change the data structure in such a way that it would have been a long, fairly difficult and tedious task to do, so I modified the Database Generator to do it for us.<br><br />
This ment that one of our programmers had to recreate the missing Dictionary file by hand. It probably took him as long to do, as it would have to make the changes, but at least we now have the Dictionary file to use for future modifications. :-D<br><br />
<br><br />
I had already written a class for use with several other projects that retrieved lists of tables, queries and fields, returned DataSets and allowed data modification using ADO.net.  It also had a very simple Dictionary file generator that I used to import a very old database into a new database using our current database structure.<br><br />
I decided that it would be a bloody good idea to enhance it in order to upgrade the Database Generator and to prove to all that it is possible to do in ADO.net.<br><br />
<br><br />
So off I went...<br><br />
<br><br />
The first snag I hit was how to retrieve the SQL string from an existing query.  I searched the internet high and low for any information on how to achieve this, but came up empty.  I posted the question on a few forums, got tired of waiting for a reply and attempted to work it out myself.<br><br />
It didn't take me long and I wish I hadn't wasted the <em>two</em> days of Googling... I basically stumbled upon the solution by accident.<br><br />
<br><br />
I then needed information on field types, lengths and various other properties.  Again I headed for Google, and came up empty, but this time I gave up looking after a very short time and went back to using my <em>own</em> brain.<br><br />
<br><br />
Which has brought me here, where I decided to start my own Blog, write about this hard to find information, make it that little bit easier to find and understand how to achieve it.<br><br />
<br><br />
My next entry will cover how I achieved this and a sample of the code I used.<br></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[ADO.NET INTERVIEW QUESTIONS]]></title>
<link>http://vinayhatwal.wordpress.com/?p=8</link>
<pubDate>Fri, 25 Jul 2008 05:06:25 +0000</pubDate>
<dc:creator>vinayhatwal</dc:creator>
<guid>http://vinayhatwal.wordpress.com/?p=8</guid>
<description><![CDATA[ 
To test a Web Service you must create a windows application or web application to consume this se]]></description>
<content:encoded><![CDATA[<p> </p>
<p class="MsoNormal" style="background:white;line-height:12pt;margin:0;"><strong><span style="font-size:9pt;color:#666b71;font-family:Verdana;">To test a Web Service you must create a windows application or web application to consume this service? It is True/False?</span></strong><span style="font-size:9pt;color:#666b71;font-family:Verdana;"><br />
FALSE<strong><span style="font-family:Verdana;">How many classes can a single.NET DLL contain?</span></strong><br />
Answer1:<br />
As many</p>
<p>Answer2:<br />
One or more</p>
<p><strong><span style="font-family:Verdana;">What are good ADO.NET object(s) to replace the ADO Recordset object?</span></strong><br />
The differences includes<br />
In ADO, the in-memory representation of data is the recordset.<br />
In ADO.net, it is the dataset<br />
A recordset looks like a single table in ADO<br />
In contrast, a dataset is a collection of one or more tables in ADO.net<br />
ADO is designed primarily for connected access<br />
ADO.net the disconnected access to the database is used<br />
In ADO you communicate with the database by making calls to an OLE DB provider.<br />
In ADO.NET you communicate with the database through a data adapter (an OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, or OracleDataAdapter object), which makes calls to an OLE DB provider or the APIs provided by the underlying data source.<br />
In ADO you cant update the database from the recordset. ADO.NET the data adapter allows you to control how the changes to the dataset are transmitted to the database.</p>
<p><strong><span style="font-family:Verdana;">On order to get assembly info which namespace we should import?</span></strong><br />
System.Reflection Namespace</p>
<p><strong><span style="font-family:Verdana;">How do you declare a static variable and what is its lifetime? Give an example.</span></strong><br />
Answer1<br />
static int Myint–The life time is during the entire application.<br />
br&#38;gt; Answer2<br />
The static modifier is used to declare a static member, which belongs to the type itself rather than to a specific object. The static modifier can be used with fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types. In C#, the static keyword indicates a class variable. In VB, the equivalent keyword is Shared. Its scoped to the class in which it occurs.</p>
<p>Example<br />
a. Static int var //in c#.net<br />
b. static void Time( ) //in c#.net</p>
<p><strong><span style="font-family:Verdana;">How do you get records number from 5 to 15 in a dataset of 100 records? Write code.</span></strong><br />
Answer1<br />
DataSet ds1=new DataSet(); String strCon=”data source=IBM-6BC8A0DACEF;initial catalog=pubs;integrated security=SSPI;persist” +” security info=False;user<br />
id=sa;workstation id=IBM-6BC8A0DACEF;packet size=4096?;<br />
String strCom1=”SELECT * FROM employee”;<br />
SqlDataAdapter sqlDa1=new SqlDataAdapter(strCom1,strCon);<br />
ds1.Tables.Add(”employee”);<br />
sqlDa1.Fill(ds1,40,50,ds1.Tables[”employee”].TableName);<br />
DataGrid dg1.DataSource=ds1.Tables[”employee”].DefaultView;<br />
dg1.DataBind();</p>
<p>Answer2<br />
OleDbConnection1.Open()<br />
OleDbDataAdapter1.Fill(DataSet21, 5, 15, “tab”)<br />
This will fill the dataset with the records starting at 5 to 15<br />
.NET Database interview questions</p>
<p><strong><span style="font-family:Verdana;">How do you call and execute a Stored Procedure in.NET? Give an example.</span></strong><br />
Answer1<br />
ds1=new DataSet();<br />
sqlCon1=new SqlConnection(connectionstring);<br />
String strCom1=”byroyalty”;<br />
sqlCom1=new SqlCommand(strCom1,sqlCon1);<br />
sqlCom1.CommandType=CommandType.StoredProcedure;<br />
sqlDa1=new SqlDataAdapter(sqlCom1);<br />
SqlParameter myPar=new SqlParameter(”@percentage”,SqlDbType.Int);<br />
sqlCom1.Parameters.Add (myPar);<br />
myPar.Value=40;<br />
sqlDa1.Fill(ds1);<br />
dg1.DataSource=ds1;<br />
dg1.DataBind();</p>
<p>Answer2<br />
Yes<br />
Dim cn as new OleDbConnection ( “Provider=Microsoft.Jet.OLEDB.4.0;”+ _<br />
“Data Source=C:\Documents and Settings\User\My Documents\Visual Studio Projects\1209\db1.mdb”+ _<br />
“User ID=Admin;”+ _<br />
“Password=;”);<br />
Dim cmd As New OleDbCommand(”Products”, cn)<br />
cmd.CommandType = CommandType.StoredProcedure<br />
Dim da As New OleDataAdapter(cmd)<br />
Dim ds As New DataSet()<br />
da.Fill(ds, “Products”)<br />
DataGrid1.DataSource = ds.Tables(”Products”)</p>
<p><strong><span style="font-family:Verdana;">What is the maximum length of a varchar in SQL Server?</span></strong><br />
Answer1<br />
VARCHAR[(n)]<br />
Null-terminated Unicode character string of length n,<br />
with a maximum of 255 characters. If n is not supplied, then 1 is assumed.</p>
<p>Answer2<br />
8000</p>
<p>Answer3<br />
The business logic is the aspx.cs or the aspx.vb where the code is being written. The presentation logic is done with .aspx extention.</p>
<p><strong><span style="font-family:Verdana;">How do you define an integer in SQL Server?</span></strong><br />
We define integer in Sql server as<br />
var_name int</p>
<p><strong><span style="font-family:Verdana;">How do you separate business logic while creating an ASP.NET application?</span></strong><br />
There are two level of asp.net debugging<br />
1. Page level debugging<br />
For this we have to edit the page level debugging enable the trace to true in the line in the html format of the page.<br />
%@ Page Language=”vb” trace=”true”AutoEventWireup=”false” Codebehind=”WebForm1.aspx.vb” Inherits=”WebApplication2.WebForm1?&#38;gt;</p>
<p>2. You can enable the debugging in the application level for this<br />
Edit the following trace value in web.config file<br />
Enable trace enabled=true.</p>
<p>If there is a calendar control to be included in each page of your application, and and we do not intend to use the Microsoft-provided calendar control, how do you develop it? Do you copy and paste the code into each and every page of your application?</p>
<p>Create the Calendar User Control<br />
The control we will create will contain a calendar control and a label which has the corresponding date and time written<br />
Steps are:-</p>
<p>Creating a CalenderControl<br />
1) To begin, open Visual Studio .NET and begin a new C# Windows Control Library.<br />
2) You may name it whatever you like, for this sample the project name will be CalenderControl</p>
<p>Using the Calender Control in a Windows Application<br />
It’s just like adding any other control like a button or a label.<br />
1) First, create a new Windows Application project named: CustomControl.<br />
2) Add a reference to the Calender Control DLL named: CalenderControl.dll.<br />
3) Now you a can customize the Toolbox:<br />
Right-Click the Toolbox&#38;gt; .NET Framework Components&#38;gt; Browse&#38;gt; select the CalenderControl.dll.<br />
4)The Calender Control is now added to the Toolbox and can be inserted in Windows Form as any other control. The control itself will take care of the date display</p>
<p><strong><span style="font-family:Verdana;">How can you deploy an asp.net application ?</span></strong><br />
You can deploy an ASP.NET Web application using any one of the following three deployment options.<br />
a) Deployment using VS.NET installer<br />
b) Using the Copy Project option in VS .NET<br />
c) XCOPY Deployment</p>
<p><strong><span style="font-family:Verdana;">Explain similarities and differences between Java and.NET?</span></strong><br />
Comparing Java and .NET is comparing apples and oranges. Either the question needs to be to compare Java and C# or J2EE and .NET.</p>
<p><strong><span style="font-family:Verdana;">What are the XML files that are important in developing an ASP.NET application?</span></strong><br />
The XML file necessary for the for developing an asp.net application is Web.config</p>
<p><strong><span style="font-family:Verdana;">Specify the best ways to store variables so that we can access them in various pages of ASP.NET application?</span></strong><br />
Declare the variables in Global.aspx</p>
<p><strong><span style="font-family:Verdana;">How many objects are there in ASP?</span></strong><br />
Answer1<br />
8 objects, they are request,response, server,application,session,file, dictionary, textstream.</p>
<p>Answer2<br />
There are 6 objects in ASP.net<br />
a) Server<br />
b) Session<br />
c) Application<br />
d) ObjectContext<br />
e) Response<br />
f) Request</p>
<p><strong><span style="font-family:Verdana;">Which DLL file is needed to be registered for ASP?</span></strong><br />
The dll needed for the ASP.net is SYSTEM.WEB.dll</p>
<p><strong><span style="font-family:Verdana;">Is there any inbuilt paging (for example shoping cart, which will show next 10 records without refreshing) in ASP? How will you do pating?</span></strong><br />
Use DataGrid control which has in-built paging features for the purpose.</p>
<p><strong><span style="font-family:Verdana;">What does Server.MapPath do?</span></strong><br />
Answer1<br />
srver.mappath() maps the path given in the argument to the server’s physical path.</p>
<p>Answer2<br />
It returns the complete(absolute) path of the file used in parameter.</p>
<p>Answer3<br />
It returns a string containing the physical path in the server’s file system that corresponds to the virtual or relative path specified by the Path argument.</p>
<p><strong><span style="font-family:Verdana;">Name atleast three methods of response object other than Redirect.</span></strong><br />
Answer1<br />
a) Response.Clear( )<br />
Clears the content of the current output stream.<br />
b) Response.Close( )<br />
Closes the network socket for the current response.<br />
c) Response.End( )<br />
Stops processing the current request and sends all buffered content to the client immediately.</p>
<p>Answer2<br />
methods of Response is Redirect a. Transfer</p>
<p><strong><span style="font-family:Verdana;">Name atleast two methods of response object other than Transfer.</span></strong><br />
a) Response.ClearContent( )<br />
Clears the content of the current output stream.<br />
b) Response.ClearHeaders( )<br />
Clears the HTTP headers from the current output stream.</p>
<p><strong><span style="font-family:Verdana;">What is State?</span></strong><br />
It is the property of the web forms.<br />
ASP.NET provides four types of state:<br />
Application state<br />
Session state<br />
Cookie state<br />
View state.</p>
<p><strong><span style="font-family:Verdana;">Explain differences between ADO and DAO.</span></strong><br />
dao- can access only access database<br />
ado- can access any databases</p>
<p><strong><span style="font-family:Verdana;">How many types of cookies are there?</span></strong><br />
2 types, persistant and impersistant.</p>
<p><strong><span style="font-family:Verdana;">How many types of cookies are there?</span></strong><br />
Answer1<br />
Two type of cookeies.<br />
a) single valued eg request.cookies(”UserName”).value=”Mahesh”<br />
b)Multivalued cookies. These are used in the way collections are used.<br />
e.g.<br />
request.cookies(”CookiName”)(”UserName”)=”Mahesh”<br />
request.cookies(”CookiName”)(”UserID”)=”ABC003?<br />
rember no value method in multivalued cooki</p>
<p>Answer2<br />
There are two types of cookies:<br />
Session cookies<br />
Persistent cookies</p>
<p><strong><span style="font-family:Verdana;">Tell few steps for optimizing (for speed and resource) ASP page/application.</span></strong><br />
Avoid mixing html code with asp code</p>
<p><strong><span style="font-family:Verdana;">Which command using Query Analyzer will give you the version of SQL Server and Operating System?</span></strong><br />
@@VERSION<br />
Returns version, processor architecture, build date, and operating system for the current installation of SQL Server.</p>
<p><strong><span style="font-family:Verdana;">How to find the SQL server version from Query Analyser</span></strong><br />
Answer1<br />
To determine which version of Microsoft SQL Server 2005 is running, connect to SQL Server 2005 by using SQL Server Management Studio, and then run the following Transact-SQL statement:<br />
SELECT SERVERPROPERTY(’productversion’), SERVERPROPERTY (’productlevel’), SERVERPROPERTY (’edition’)<br />
The results are:<br />
• The product version (for example, “9.00.1399.06?)<br />
. • The product level (for example, “RTM”).<br />
• The edition (for example, “Enterprise Edition”).<br />
For example, the result looks similar to:<br />
9.00.1399.06 RTM Enterprise Edition</p>
<p><strong><span style="font-family:Verdana;">How to determine which version of SQL Server 2000 is running</span></strong><br />
To determine which version of SQL Server 2000 is running, connect to SQL Server 2000 by using Query Analyzer, and then run the following code:<br />
SELECT SERVERPROPERTY(’productversion’), SERVERPROPERTY (’productlevel’), SERVERPROPERTY (’edition’)<br />
The results are:<br />
• The product version (for example, 8.00.534).<br />
• The product level (for example, “RTM” or “SP2?).<br />
• The edition (for example, “Standard Edition”). For example, the result looks similar to<br />
:<br />
8.00.534 RTM Standard Edition</p>
<p>Answer2<br />
One can also use SELECT @@Version where the result would look like<br />
Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)<br />
Oct 14 2005 00:33:37<br />
Copyright (c) 1988-2005 Microsoft Corporation<br />
Express Edition on Windows NT 5.1 (Build 2600: Service Pack 2)</p>
<p><strong><span style="font-family:Verdana;">Using query analyzer, name 3 ways you can get an accurate count of the number of records in a table.</span></strong><br />
Answer1.<br />
a. Select count(*) from table1<br />
b. SELECT object_name(id) ,rowcnt FROM sysindexes WHERE indid IN (1,0) AND OBJECTPROPERTY(id, ‘IsUserTable’) = 1<br />
c. exec sp_table_validation @table = ‘authors’</p>
<p><span style="font-size:9pt;color:#666b71;font-family:Verdana;">Answer2.<br />
SELECT count( * ) as totalrecords FROM employee<br />
This will display total records under the name totalrecords in the table employee<br />
use COUNT_BIG<br />
Returns the number of items in a group.<br />
@@ROWCOUNT<br />
Returns the number of rows affected by the last statement.<br />
Use this statement after an SQL select * statement, to retrieve the total number of rows in the table</p>
<p></span></span></p>
<p> </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="background:white;line-height:12pt;margin:0;"><strong><span style="font-size:9pt;color:#666b71;font-family:Verdana;">To test a Web Service you must create a windows application or web application to consume this service? It is True/False?</span></strong><span style="font-size:9pt;color:#666b71;font-family:Verdana;"><br />
FALSE<strong><span style="font-family:Verdana;">How many classes can a single.NET DLL contain?</span></strong><br />
Answer1:<br />
As many</p>
<p>Answer2:<br />
One or more</p>
<p><strong><span style="font-family:Verdana;">What are good ADO.NET object(s) to replace the ADO Recordset object?</span></strong><br />
The differences includes<br />
In ADO, the in-memory representation of data is the recordset.<br />
In ADO.net, it is the dataset<br />
A recordset looks like a single table in ADO<br />
In contrast, a dataset is a collection of one or more tables in ADO.net<br />
ADO is designed primarily for connected access<br />
ADO.net the disconnected access to the database is used<br />
In ADO you communicate with the database by making calls to an OLE DB provider.<br />
In ADO.NET you communicate with the database through a data adapter (an OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, or OracleDataAdapter object), which makes calls to an OLE DB provider or the APIs provided by the underlying data source.<br />
In ADO you cant update the database from the recordset. ADO.NET the data adapter allows you to control how the changes to the dataset are transmitted to the database.</p>
<p><strong><span style="font-family:Verdana;">On order to get assembly info which namespace we should import?</span></strong><br />
System.Reflection Namespace</p>
<p><strong><span style="font-family:Verdana;">How do you declare a static variable and what is its lifetime? Give an example.</span></strong><br />
Answer1<br />
static int Myint–The life time is during the entire application.<br />
br&#38;gt; Answer2<br />
The static modifier is used to declare a static member, which belongs to the type itself rather than to a specific object. The static modifier can be used with fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types. In C#, the static keyword indicates a class variable. In VB, the equivalent keyword is Shared. Its scoped to the class in which it occurs.</p>
<p>Example<br />
a. Static int var //in c#.net<br />
b. static void Time( ) //in c#.net</p>
<p><strong><span style="font-family:Verdana;">How do you get records number from 5 to 15 in a dataset of 100 records? Write code.</span></strong><br />
Answer1<br />
DataSet ds1=new DataSet(); String strCon=”data source=IBM-6BC8A0DACEF;initial catalog=pubs;integrated security=SSPI;persist” +” security info=False;user<br />
id=sa;workstation id=IBM-6BC8A0DACEF;packet size=4096?;<br />
String strCom1=”SELECT * FROM employee”;<br />
SqlDataAdapter sqlDa1=new SqlDataAdapter(strCom1,strCon);<br />
ds1.Tables.Add(”employee”);<br />
sqlDa1.Fill(ds1,40,50,ds1.Tables[”employee”].TableName);<br />
DataGrid dg1.DataSource=ds1.Tables[”employee”].DefaultView;<br />
dg1.DataBind();</p>
<p>Answer2<br />
OleDbConnection1.Open()<br />
OleDbDataAdapter1.Fill(DataSet21, 5, 15, “tab”)<br />
This will fill the dataset with the records starting at 5 to 15<br />
.NET Database interview questions</p>
<p><strong><span style="font-family:Verdana;">How do you call and execute a Stored Procedure in.NET? Give an example.</span></strong><br />
Answer1<br />
ds1=new DataSet();<br />
sqlCon1=new SqlConnection(connectionstring);<br />
String strCom1=”byroyalty”;<br />
sqlCom1=new SqlCommand(strCom1,sqlCon1);<br />
sqlCom1.CommandType=CommandType.StoredProcedure;<br />
sqlDa1=new SqlDataAdapter(sqlCom1);<br />
SqlParameter myPar=new SqlParameter(”@percentage”,SqlDbType.Int);<br />
sqlCom1.Parameters.Add (myPar);<br />
myPar.Value=40;<br />
sqlDa1.Fill(ds1);<br />
dg1.DataSource=ds1;<br />
dg1.DataBind();</p>
<p>Answer2<br />
Yes<br />
Dim cn as new OleDbConnection ( “Provider=Microsoft.Jet.OLEDB.4.0;”+ _<br />
“Data Source=C:\Documents and Settings\User\My Documents\Visual Studio Projects\1209\db1.mdb”+ _<br />
“User ID=Admin;”+ _<br />
“Password=;”);<br />
Dim cmd As New OleDbCommand(”Products”, cn)<br />
cmd.CommandType = CommandType.StoredProcedure<br />
Dim da As New OleDataAdapter(cmd)<br />
Dim ds As New DataSet()<br />
da.Fill(ds, “Products”)<br />
DataGrid1.DataSource = ds.Tables(”Products”)</p>
<p><strong><span style="font-family:Verdana;">What is the maximum length of a varchar in SQL Server?</span></strong><br />
Answer1<br />
VARCHAR[(n)]<br />
Null-terminated Unicode character string of length n,<br />
with a maximum of 255 characters. If n is not supplied, then 1 is assumed.</p>
<p>Answer2<br />
8000</p>
<p>Answer3<br />
The business logic is the aspx.cs or the aspx.vb where the code is being written. The presentation logic is done with .aspx extention.</p>
<p><strong><span style="font-family:Verdana;">How do you define an integer in SQL Server?</span></strong><br />
We define integer in Sql server as<br />
var_name int</p>
<p><strong><span style="font-family:Verdana;">How do you separate business logic while creating an ASP.NET application?</span></strong><br />
There are two level of asp.net debugging<br />
1. Page level debugging<br />
For this we have to edit the page level debugging enable the trace to true in the line in the html format of the page.<br />
%@ Page Language=”vb” trace=”true”AutoEventWireup=”false” Codebehind=”WebForm1.aspx.vb” Inherits=”WebApplication2.WebForm1?&#38;gt;</p>
<p>2. You can enable the debugging in the application level for this<br />
Edit the following trace value in web.config file<br />
Enable trace enabled=true.</p>
<p>If there is a calendar control to be included in each page of your application, and and we do not intend to use the Microsoft-provided calendar control, how do you develop it? Do you copy and paste the code into each and every page of your application?</p>
<p>Create the Calendar User Control<br />
The control we will create will contain a calendar control and a label which has the corresponding date and time written<br />
Steps are:-</p>
<p>Creating a CalenderControl<br />
1) To begin, open Visual Studio .NET and begin a new C# Windows Control Library.<br />
2) You may name it whatever you like, for this sample the project name will be CalenderControl</p>
<p>Using the Calender Control in a Windows Application<br />
It’s just like adding any other control like a button or a label.<br />
1) First, create a new Windows Application project named: CustomControl.<br />
2) Add a reference to the Calender Control DLL named: CalenderControl.dll.<br />
3) Now you a can customize the Toolbox:<br />
Right-Click the Toolbox&#38;gt; .NET Framework Components&#38;gt; Browse&#38;gt; select the CalenderControl.dll.<br />
4)The Calender Control is now added to the Toolbox and can be inserted in Windows Form as any other control. The control itself will take care of the date display</p>
<p><strong><span style="font-family:Verdana;">How can you deploy an asp.net application ?</span></strong><br />
You can deploy an ASP.NET Web application using any one of the following three deployment options.<br />
a) Deployment using VS.NET installer<br />
b) Using the Copy Project option in VS .NET<br />
c) XCOPY Deployment</p>
<p><strong><span style="font-family:Verdana;">Explain similarities and differences between Java and.NET?</span></strong><br />
Comparing Java and .NET is comparing apples and oranges. Either the question needs to be to compare Java and C# or J2EE and .NET.</p>
<p><strong><span style="font-family:Verdana;">What are the XML files that are important in developing an ASP.NET application?</span></strong><br />
The XML file necessary for the for developing an asp.net application is Web.config</p>
<p><strong><span style="font-family:Verdana;">Specify the best ways to store variables so that we can access them in various pages of ASP.NET application?</span></strong><br />
Declare the variables in Global.aspx</p>
<p><strong><span style="font-family:Verdana;">How many objects are there in ASP?</span></strong><br />
Answer1<br />
8 objects, they are request,response, server,application,session,file, dictionary, textstream.</p>
<p>Answer2<br />
There are 6 objects in ASP.net<br />
a) Server<br />
b) Session<br />
c) Application<br />
d) ObjectContext<br />
e) Response<br />
f) Request</p>
<p><strong><span style="font-family:Verdana;">Which DLL file is needed to be registered for ASP?</span></strong><br />
The dll needed for the ASP.net is SYSTEM.WEB.dll</p>
<p><strong><span style="font-family:Verdana;">Is there any inbuilt paging (for example shoping cart, which will show next 10 records without refreshing) in ASP? How will you do pating?</span></strong><br />
Use DataGrid control which has in-built paging features for the purpose.</p>
<p><strong><span style="font-family:Verdana;">What does Server.MapPath do?</span></strong><br />
Answer1<br />
srver.mappath() maps the path given in the argument to the server’s physical path.</p>
<p>Answer2<br />
It returns the complete(absolute) path of the file used in parameter.</p>
<p>Answer3<br />
It returns a string containing the physical path in the server’s file system that corresponds to the virtual or relative path specified by the Path argument.</p>
<p><strong><span style="font-family:Verdana;">Name atleast three methods of response object other than Redirect.</span></strong><br />
Answer1<br />
a) Response.Clear( )<br />
Clears the content of the current output stream.<br />
b) Response.Close( )<br />
Closes the network socket for the current response.<br />
c) Response.End( )<br />
Stops processing the current request and sends all buffered content to the client immediately.</p>
<p>Answer2<br />
methods of Response is Redirect a. Transfer</p>
<p><strong><span style="font-family:Verdana;">Name atleast two methods of response object other than Transfer.</span></strong><br />
a) Response.ClearContent( )<br />
Clears the content of the current output stream.<br />
b) Response.ClearHeaders( )<br />
Clears the HTTP headers from the current output stream.</p>
<p><strong><span style="font-family:Verdana;">What is State?</span></strong><br />
It is the property of the web forms.<br />
ASP.NET provides four types of state:<br />
Application state<br />
Session state<br />
Cookie state<br />
View state.</p>
<p><strong><span style="font-family:Verdana;">Explain differences between ADO and DAO.</span></strong><br />
dao- can access only access database<br />
ado- can access any databases</p>
<p><strong><span style="font-family:Verdana;">How many types of cookies are there?</span></strong><br />
2 types, persistant and impersistant.</p>
<p><strong><span style="font-family:Verdana;">How many types of cookies are there?</span></strong><br />
Answer1<br />
Two type of cookeies.<br />
a) single valued eg request.cookies(”UserName”).value=”Mahesh”<br />
b)Multivalued cookies. These are used in the way collections are used.<br />
e.g.<br />
request.cookies(”CookiName”)(”UserName”)=”Mahesh”<br />
request.cookies(”CookiName”)(”UserID”)=”ABC003?<br />
rember no value method in multivalued cooki</p>
<p>Answer2<br />
There are two types of cookies:<br />
Session cookies<br />
Persistent cookies</p>
<p><strong><span style="font-family:Verdana;">Tell few steps for optimizing (for speed and resource) ASP page/application.</span></strong><br />
Avoid mixing html code with asp code</p>
<p><strong><span style="font-family:Verdana;">Which command using Query Analyzer will give you the version of SQL Server and Operating System?</span></strong><br />
@@VERSION<br />
Returns version, processor architecture, build date, and operating system for the current installation of SQL Server.</p>
<p><strong><span style="font-family:Verdana;">How to find the SQL server version from Query Analyser</span></strong><br />
Answer1<br />
To determine which version of Microsoft SQL Server 2005 is running, connect to SQL Server 2005 by using SQL Server Management Studio, and then run the following Transact-SQL statement:<br />
SELECT SERVERPROPERTY(’productversion’), SERVERPROPERTY (’productlevel’), SERVERPROPERTY (’edition’)<br />
The results are:<br />
• The product version (for example, “9.00.1399.06?)<br />
. • The product level (for example, “RTM”).<br />
• The edition (for example, “Enterprise Edition”).<br />
For example, the result looks similar to:<br />
9.00.1399.06 RTM Enterprise Edition</p>
<p><strong><span style="font-family:Verdana;">How to determine which version of SQL Server 2000 is running</span></strong><br />
To determine which version of SQL Server 2000 is running, connect to SQL Server 2000 by using Query Analyzer, and then run the following code:<br />
SELECT SERVERPROPERTY(’productversion’), SERVERPROPERTY (’productlevel’), SERVERPROPERTY (’edition’)<br />
The results are:<br />
• The product version (for example, 8.00.534).<br />
• The product level (for example, “RTM” or “SP2?).<br />
• The edition (for example, “Standard Edition”). For example, the result looks similar to<br />
:<br />
8.00.534 RTM Standard Edition</p>
<p>Answer2<br />
One can also use SELECT @@Version where the result would look like<br />
Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)<br />
Oct 14 2005 00:33:37<br />
Copyright (c) 1988-2005 Microsoft Corporation<br />
Express Edition on Windows NT 5.1 (Build 2600: Service Pack 2)</p>
<p><strong><span style="font-family:Verdana;">Using query analyzer, name 3 ways you can get an accurate count of the number of records in a table.</span></strong><br />
Answer1.<br />
a. Select count(*) from table1<br />
b. SELECT object_name(id) ,rowcnt FROM sysindexes WHERE indid IN (1,0) AND OBJECTPROPERTY(id, ‘IsUserTable’) = 1<br />
c. exec sp_table_validation @table = ‘authors’</p>
<p><span style="font-size:9pt;color:#666b71;font-family:Verdana;">Answer2.<br />
SELECT count( * ) as totalrecords FROM employee<br />
This will display total records under the name totalrecords in the table employee<br />
use COUNT_BIG<br />
Returns the number of items in a group.<br />
@@ROWCOUNT<br />
Returns the number of rows affected by the last statement.<br />
Use this statement after an SQL select * statement, to retrieve the total number of rows in the table</p>
<p></span></span></p>
<p> </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Membuat Program input dan edit data dengan VB.NET 2005 dan SQL Server 2005 (hampir 100% murni coding)]]></title>
<link>http://aprijunaidi.wordpress.com/?p=45</link>
<pubDate>Thu, 24 Jul 2008 05:05:28 +0000</pubDate>
<dc:creator>aprijunaidi</dc:creator>
<guid>http://aprijunaidi.wordpress.com/?p=45</guid>
<description><![CDATA[ 
 
Program Input, Edit, Hapus (Manipulasi data) merupakan program standar yang selalu ada pada saat]]></description>
<content:encoded><![CDATA[<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Program Input, Edit, Hapus (Manipulasi data) merupakan program standar yang selalu ada pada saat seorang programmer membuat aplikasi.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Kebisaan membuat program dari zaman Basic, Pascal, clipper, foxpro sampai ke<span> </span>Visual Basic 5 dan Visual Basic 6 yang selalu mengandalkan kode program dalam membangun program, bagi saya masih terbawa bawa ke era Visual yang telah didukung dengan Wizard.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Pada artikel kali ini saya coba memaparkan cara membuat program Input, Edit, Hapus dengan mengambil contoh pengolahan data supplier, hampir 100% saya pakai code program.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Contoh yang dibahas sifatnya sangat dasar sekali, jadi untuk rekan rekan yang sudah sangat berpengalaman dalam pemrograman dimohon saran dan info yang membangun demi kebaikan kemampuan programming dimasa datang. </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Untuk rekan pemula mudahan mudahan artikel ini bisa membantu dalam memperdalam pengetahuan programming</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Mari kita mulai saja.</span><!--more--></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Siapkan sebuah database di SQL Server 2005, pada komputer saya servernya saya beri nama ISLAM, dengan nama database GUDANG</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Untuk server pembaca silahkan sesuaikan sendiri sesuai keinginan.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Kita lanjutkan</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Buat table supplier dengan susunan field seperti gambar berikut :</span></p>
<p class="MsoNormal"><a href="http://aprijunaidi.files.wordpress.com/2008/07/desaintablesupplier.png"><img class="alignnone size-medium wp-image-49" src="http://aprijunaidi.wordpress.com/files/2008/07/desaintablesupplier.png?w=300" alt="" width="300" height="178" /></a></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><!--[if gte vml 1]&#62;                    &#60;![endif]--><!--[if !vml]--><!--[endif]--></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Sekarang aktifkan Visual Basic.NET 2005 dan buat sebuah project baru namanya juga terserah anda. (saya sendiri memberi nama project ini GUDANG)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Siapkan sebuah Module baru yang berfungsi untuk membuat koneksi kedatabase atau tempat menyimpan fungsi atau prosedur yang kita butuhkan dalam pembuatan program.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Langkah pembuatan module : klik kanan nama project yang ada di Window Solution Explorer, lalu pilih <strong>Add --&#62; Module. </strong><span> </span>Secara default VB akan memberi nama Module1.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">berikut ini gambar Solution Explorer :</span></p>
<p class="MsoNormal"><a href="http://aprijunaidi.files.wordpress.com/2008/07/solution-explorer1.png"><img class="alignnone size-medium wp-image-51" src="http://aprijunaidi.wordpress.com/files/2008/07/solution-explorer1.png?w=141" alt="" width="141" height="300" /></a></p>
<p class="MsoNormal">
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><!--[if gte vml 1]&#62;  &#60;![endif]--><!--[if !vml]--><!--[endif]--></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Pada jendela Code program Module1 masukkan kode berikut :</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Imports</span><span style="font-size:10pt;font-family:&#34;"> System.Data.SqlClient</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Module</span><span style="font-size:10pt;font-family:&#34;"> Module1</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Public</span> <span style="color:blue;">Function</span> Koneksi() <span style="color:blue;">As</span> SqlConnection</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Dim</span> </span><span style="font-size:10pt;font-family:&#34;">Conn</span><span style="font-size:10pt;font-family:&#34;"> <span style="color:blue;">As</span> <span style="color:blue;">New</span> SqlConnection</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span></span><span style="font-size:10pt;font-family:&#34;">Conn</span><span style="font-size:10pt;font-family:&#34;"> = <span style="color:blue;">New</span> SqlConnection(<span style="color:maroon;">"server=islam; database=gudang; user=sa;password=intan;"</span>)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>Conn.Open()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span></span><span style="color:blue;"><span style="font-size:10pt;font-family:&#34;">Return</span></span><span style="font-size:10pt;font-family:&#34;"> </span><span style="font-size:10pt;font-family:&#34;">Conn</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Function</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">End</span><span style="font-size:10pt;font-family:&#34;"> <span style="color:blue;">Module</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Sekali lagi untuk nama server, database,<span> </span>user dan password sesuaikan dengan komputer yang anda pakai.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Tahap selanjutnya siapkan form baru dengan contoh disain seperti gambar berikut.</span></p>
<p class="MsoNormal"><a href="http://aprijunaidi.files.wordpress.com/2008/07/supplier.png"><img class="alignnone size-medium wp-image-50" src="http://aprijunaidi.wordpress.com/files/2008/07/supplier.png?w=300" alt="" width="300" height="222" /></a></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><!--[if gte vml 1]&#62;  &#60;![endif]--><!--[if !vml]--><!--[endif]--></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Komponen yang ada pada form terdiri dari 6 Label (text label sesuaikan dengan gambar), </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">6 Buah Textbox Masing masing diberi nama :</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">TextKode</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">TextNama</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">TextAlamat</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">TextTelepon</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">TextKontakPerson</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">TextEmail</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">6 Buah Button, masing diberi nama :</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">ButtonTambah</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">ButtonSimpan</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">ButtonHapus </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">ButtonUpdate</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">ButtunKeluar</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Buttun1 (Loading data)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">1 Buah DatagridView dengan nama <strong>GridSupplier</strong>.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-family:&#34;">Saatnya Coding</span></strong><span style="font-size:10pt;font-family:&#34;">…...,</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Setelah semua komponen tersusun dalam Form saat kita melakukan coding program.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Pada Menu Bar, pilih menu View </span><span style="font-size:10pt;font-family:Wingdings;"><span>à</span></span><span style="font-size:10pt;font-family:&#34;"> Code</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Pada bagian atas ketikan kode berikut untuk meng-import Class Data SQL sehingga kita bisa melakukan koneksi ke database.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Imports</span><span style="font-size:10pt;font-family:&#34;"> System.Data.SqlClient</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Selanjutnya pelajari code program berikut baris perbaris sambil memperhatikan komentar kode program yang saya sisipkan pada setiap prosedur.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Kode komentar selalu diawali dengan tanda kutip satu (‘)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Public</span><span style="font-size:10pt;font-family:&#34;"> <span style="color:blue;">Class</span> Supplier</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ Siapkan variabel keneksi</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Dim</span><span style="font-size:10pt;font-family:&#34;"> koneksi = Module1.Koneksi</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘Prosedur load form (aktifkan denfan double klik pada form)</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>Private</span><span style="font-size:10pt;font-family:&#34;"> <span style="color:blue;">Sub</span> Supplier_Load(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.Object, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.EventArgs) <span style="color:blue;">Handles</span> <span style="color:blue;">MyBase</span>.Load</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>‘ panggil prosedur PanggilData</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>PanggilData()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonSimpan.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonHapus.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonUpdate.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;"> </span></strong></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;"><span> </span>‘Prosedur membuat datagridview<span> </span>memiliki warna Alternate </span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Sub</span> GridBerwarna()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">With</span> <span style="color:blue;">Me</span>.GridSupplier</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>.RowsDefaultCellStyle.BackColor = Color.BlanchedAlmond</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>.AlternatingRowsDefaultCellStyle.BackColor = Color.Azure</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">With</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;"><span> </span>‘ Prosedur panggildata</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Sub</span> PanggilData()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Dim</span> Adapter <span style="color:blue;">As</span> <span style="color:blue;">New</span> SqlDataAdapter(<span style="color:maroon;">"select * from supplier"</span>, Module1.Koneksi)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Dim</span> dt <span style="color:blue;">As</span> <span style="color:blue;">New</span> DataTable(<span style="color:maroon;">"Supplier"</span>)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>Adapter.Fill(dt)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>GridSupplier.DataSource = dt</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> GridBerwarna()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;"><span> </span>‘Prosedur Form kosong (berfungsi untuk mengosongkan TetxBox dangan pengaturan focus</span></strong><span style="font-size:10pt;font-family:&#34;">)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Sub</span> FormKosong()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextKode.Text = <span style="color:maroon;">""</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextNama.Text = <span style="color:maroon;">""</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextAlamat.Text = <span style="color:maroon;">""</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextTelepon.Text = <span style="color:maroon;">""</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextKontakPerson.Text = <span style="color:maroon;">""</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextEmail.Text = <span style="color:maroon;">""</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextKode.Focus()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;"><span> </span>‘Prosedur mengaktifkan TextBox </span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Sub</span> FormHidup()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextKode.Enabled = <span style="color:blue;">True</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextNama.Enabled = <span style="color:blue;">True</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextAlamat.Enabled = <span style="color:blue;">True</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextTelepon.Enabled = <span style="color:blue;">True</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextKontakPerson.Enabled = <span style="color:blue;">True</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextEmail.Enabled = <span style="color:blue;">True</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><strong>‘Prosedure Mengatur Button dan Textbox</strong></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Sub</span> FormNormal()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> FormKosong()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonTambah.Enabled = <span style="color:blue;">True</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonHapus.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonSimpan.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonKeluar.Text = <span style="color:maroon;">"&#38;Keluar"</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><strong>‘Prosedur untuk tambah data</strong></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> ButtonTambah_Click(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.Object, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.EventArgs) <span style="color:blue;">Handles</span> ButtonTambah.Click</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> FormHidup()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> FormKosong()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> PanggilData()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonSimpan.Enabled = <span style="color:blue;">True</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonTambah.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonHapus.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonUpdate.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonKeluar.Text = <span style="color:maroon;">"&#38;Normal"</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextKode.Focus()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘Prosedur untuk simpan data</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> ButtonSimpan_Click(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.Object, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.EventArgs) <span style="color:blue;">Handles</span> ButtonSimpan.Click</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Dim</span> Sql <span style="color:blue;">As</span> <span style="color:blue;">String</span> = <span style="color:blue;">String</span>.Empty</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><strong><span style="color:green;">'Cek Kode</span></strong></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><strong>‘Uji data apakah textKode tidak kosong</strong></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>If</span><span style="font-size:10pt;font-family:&#34;"> TextKode.Text &#60;&#62; <span style="color:maroon;">""</span> <span style="color:blue;">Then</span></span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;"><span> </span>'Jika tidak kosong tambahkan data</span></strong></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;"> </span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span> </span>Sql = <span style="color:maroon;">"INSERT INTO Supplier(KodeSupplier,NamaSupplier,AlamatSupplier,Telepon,KontakPerson,email)"</span> _</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>&#38; <span style="color:maroon;">" VALUES ('"</span> &#38; TextKode.Text &#38; <span style="color:maroon;">"','"</span> &#38; TextNama.Text &#38; <span style="color:maroon;">"', '"</span> &#38; TextAlamat.Text &#38; <span style="color:maroon;">"', '"</span> _</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>&#38; TextTelepon.Text &#38; <span style="color:maroon;">"', '"</span> &#38; TextKontakPerson.Text &#38; <span style="color:maroon;">"', '"</span> &#38; TextEmail.Text &#38; <span style="color:maroon;">"')"</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ Periksa hati-hati tanda kutip untuk setiap variabel, salah ketik mengakibatkan query anda tidak akan terbaca.</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ Persiapan execusi Query Insert</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Dim</span><span style="font-size:10pt;font-family:&#34;"> command <span style="color:blue;">As</span> <span style="color:blue;">New</span> SqlCommand(Sql, Module1.Koneksi)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">command.ExecuteNonQuery()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Module1.Koneksi.Close()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ sampaikan pesan bahwa data telah tersimpan.</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>MessageBox.Show(<span style="color:maroon;">"Data dengan kode "</span> &#38; TextKode.Text &#38; <span style="color:maroon;">" Sudah disimpan"</span>, <span style="color:maroon;">"Simpan data Sukses"</span>, MessageBoxButtons.OK, MessageBoxIcon.Information)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ sampaikan juga pesan jika penyimpanan gagal.</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Else</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>MessageBox.Show(<span style="color:maroon;">"Isikan dulu data"</span>, <span style="color:maroon;">"Simpan Gagal"</span>, MessageBoxButtons.OK, MessageBoxIcon.Information)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextKode.Focus()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">If</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ Panggil prosedur FormKosong dan prosedur panggil data.</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> FormKosong()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> PanggilData()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ ini prosedur untuk mengganti tab jadi enter dan prosedur untuk mencari apakah data pada text kode sudah pernah ada atau belum untuk menghindari redudansi data.</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> TextKode_KeyPress(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> <span style="color:blue;">Object</span>, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.Windows.Forms.KeyPressEventArgs) <span style="color:blue;">Handles</span> TextKode.KeyPress</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">If</span> e.KeyChar = Chr(Keys.Enter) <span style="color:blue;">Then</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><strong><span style="color:green;">'mengirim key tab</span></strong></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>SendKeys.Send(<span style="color:maroon;">"{tab}"</span>)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">If</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><strong><span style="color:green;">'buat koneksi untuk pencarian data yang sudah ada</span></strong></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Dim</span> Adapter <span style="color:blue;">As</span> <span style="color:blue;">New</span> SqlDataAdapter(<span style="color:maroon;">"SELECT * from Supplier where KodeSupplier =<span> </span>'"</span> _</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>&#38; TextKode.Text &#38; <span style="color:maroon;">"'"</span>, Module1.Koneksi)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Dim</span> dt <span style="color:blue;">As</span> <span style="color:blue;">New</span> DataTable(<span style="color:maroon;">"Supplier"</span>)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>Adapter.Fill(dt)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><strong><span style="color:green;">'Jika data yang dicari ada</span></strong></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">If</span> dt.Rows.Count &#60;&#62; 0 <span style="color:blue;">Then</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>MessageBox.Show(<span style="color:maroon;">"Data dengan kode "</span> &#38; TextKode.Text &#38; <span style="color:maroon;">" Sudah ada, inputkan data lain"</span>, <span style="color:maroon;">"Ditemukan data yang sama"</span>, MessageBoxButtons.OK, MessageBoxIcon.Information)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextKode.Text = <span style="color:maroon;">" "</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">If</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>GridSupplier.DataSource = dt</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ ini prosedur untuk mengganti tab jadi enter</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> TextNama_KeyPress(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> <span style="color:blue;">Object</span>, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.Windows.Forms.KeyPressEventArgs) <span style="color:blue;">Handles</span> TextNama.KeyPress</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:green;">'tab to enter</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">If</span> e.KeyChar = Chr(Keys.Enter) <span style="color:blue;">Then</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:green;">'mengirim key tab</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>SendKeys.Send(<span style="color:maroon;">"{tab}"</span>)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">If</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ ini prosedur untuk mengganti tab jadi enter</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> TextAlamat_KeyPress(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> <span style="color:blue;">Object</span>, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.Windows.Forms.KeyPressEventArgs) <span style="color:blue;">Handles</span> TextAlamat.KeyPress</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:green;">'tab to enter</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">If</span> e.KeyChar = Chr(Keys.Enter) <span style="color:blue;">Then</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:green;">'mengirim key tab</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>SendKeys.Send(<span style="color:maroon;">"{tab}"</span>)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">If</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ ini prosedur untuk mengganti tab jadi enter</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> TextTelepon_KeyPress(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> <span style="color:blue;">Object</span>, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.Windows.Forms.KeyPressEventArgs) <span style="color:blue;">Handles</span> TextTelepon.KeyPress</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:green;">'tab to enter</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">If</span> e.KeyChar = Chr(Keys.Enter) <span style="color:blue;">Then</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:green;">'mengirim key tab</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>SendKeys.Send(<span style="color:maroon;">"{tab}"</span>)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">If</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ ini prosedur untuk mengganti tab jadi enter</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> TextKontakPerson_KeyPress(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> <span style="color:blue;">Object</span>, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.Windows.Forms.KeyPressEventArgs) <span style="color:blue;">Handles</span> TextKontakPerson.KeyPress</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:green;">'tab to enter</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">If</span> e.KeyChar = Chr(Keys.Enter) <span style="color:blue;">Then</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:green;">'mengirim key tab</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>SendKeys.Send(<span style="color:maroon;">"{tab}"</span>)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">If</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ ini prosedur untuk mengganti tab jadi enter</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> TextEmail_KeyPress(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> <span style="color:blue;">Object</span>, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.Windows.Forms.KeyPressEventArgs) <span style="color:blue;">Handles</span> TextEmail.KeyPress</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:green;">'tab to enter</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">If</span> e.KeyChar = Chr(Keys.Enter) <span style="color:blue;">Then</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:green;">'mengirim key tab</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>SendKeys.Send(<span style="color:maroon;">"{tab}"</span>)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">If</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘prosedur untuk menghapus data</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> ButtonHapus_Click(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.Object, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.EventArgs) <span style="color:blue;">Handles</span> ButtonHapus.Click</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">If</span> GridSupplier.CurrentRow.Index &#62; -1 <span style="color:blue;">Then</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Dim</span> Sql <span style="color:blue;">As</span> <span style="color:blue;">String</span> = <span style="color:blue;">String</span>.Empty</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>Sql = <span style="color:maroon;">"Delete from Supplier where KodeSupplier =<span> </span>'"</span> &#38; TextKode.Text &#38; <span style="color:maroon;">"'"</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Dim</span> command <span style="color:blue;">As</span> <span style="color:blue;">New</span> SqlCommand(Sql, Module1.Koneksi)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>command.ExecuteNonQuery()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>Module1.Koneksi.Close()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>MessageBox.Show(<span style="color:maroon;">"Data dengan kode "</span> &#38; TextKode.Text &#38; <span style="color:maroon;">" Sudah dihapus"</span>, <span style="color:maroon;">"Penghapusan Sukses"</span>, MessageBoxButtons.OK, MessageBoxIcon.Information)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> FormKosong()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> PanggilData()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonHapus.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonUpdate.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Else</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>MessageBox.Show(<span style="color:maroon;">"Pilih dulu data yang akan dihapus"</span>, <span style="color:maroon;">"Tidak ada data yang akan dihapus"</span>, MessageBoxButtons.OK, MessageBoxIcon.Information)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">If</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘prosedur untuk Update data</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> ButtonUpdate_Click(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.Object, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.EventArgs) <span style="color:blue;">Handles</span> ButtonUpdate.Click</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Dim</span> Sql <span style="color:blue;">As</span> <span style="color:blue;">String</span> = <span style="color:blue;">String</span>.Empty</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:green;">'Cek Kode</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:green;">'Update</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>Sql = <span style="color:maroon;">"UPDATE Supplier SET KodeSupplier= '"</span> &#38; TextKode.Text &#38; <span style="color:maroon;">"',"</span> _</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>&#38; <span style="color:maroon;">"NamaSupplier='"</span> &#38; TextNama.Text &#38; <span style="color:maroon;">"',AlamatSupplier = '"</span> &#38; TextAlamat.Text &#38; <span style="color:maroon;">"',"</span> _</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>&#38; <span style="color:maroon;">"Telepon='"</span> &#38; TextTelepon.Text &#38; <span style="color:maroon;">"',KontakPerson = '"</span> &#38; TextKontakPerson.Text &#38; <span style="color:maroon;">"',"</span> _</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>&#38; <span style="color:maroon;">"email = '"</span> &#38; TextEmail.Text &#38; <span style="color:maroon;">"' WHERE kodeSupplier = '"</span> &#38; TextKode.Text &#38; <span style="color:maroon;">"'"</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Dim</span> command <span style="color:blue;">As</span> <span style="color:blue;">New</span> SqlCommand(Sql, Module1.Koneksi)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>command.ExecuteNonQuery()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>Module1.Koneksi.Close()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span> </span>MessageBox.Show(<span style="color:maroon;">"Data dengan kode "</span> &#38; TextKode.Text &#38; <span style="color:maroon;">" Sudah diupdate"</span>, <span style="color:maroon;">"Update data Sukses"</span>, MessageBoxButtons.OK, MessageBoxIcon.Information)</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> FormKosong()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> PanggilData()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonHapus.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonUpdate.Enabled = <span style="color:blue;">False</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> ButtonKeluar_Click(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.Object, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.EventArgs) <span style="color:blue;">Handles</span> ButtonKeluar.Click</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">If</span> ButtonKeluar.Text = <span style="color:maroon;">"&#38;Keluar"</span> <span style="color:blue;">Then</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Me</span>.Close()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Else</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> FormNormal()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">If</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘prosedur untuk loading data ke dataqridview (refresh data, setelah dilakukan query </span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> Button1_Click(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.Object, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.EventArgs) <span style="color:blue;">Handles</span> Button1.Click</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">Call</span> PanggilData()</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">‘ini prosedur yang sangat berperan,karena prosedure ini akan membuat setiap baris yang cel yang kita klik pada data grid view, maka isi dari setiap field akan dikirim kedalam textbox, sehingga kita dapat melakukan manipulasi data.</span></strong></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&#34;">Prosedure ini mirip dengan Binding manager, Insyallah akan kita bahas pada artikel berikutnya.</span></strong></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Private</span><span style="font-size:10pt;font-family:&#34;"> <span style="color:blue;">Sub</span> GridSupplier_CellClick(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> <span style="color:blue;">Object</span>, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.Windows.Forms.DataGridViewCellEventArgs) <span style="color:blue;">Handles</span> GridSupplier.CellClick</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span> </span><span style="color:blue;">Dim</span> i <span style="color:blue;">As</span> <span style="color:blue;">Integer</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>i = GridSupplier.CurrentRow.Index</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextKode.Text = GridSupplier.Item(0, i).Value</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextNama.Text = GridSupplier.Item(1, i).Value</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextAlamat.Text = GridSupplier.Item(2, i).Value</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextTelepon.Text = GridSupplier.Item(3, i).Value</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextKontakPerson.Text = GridSupplier.Item(4, i).Value</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>TextEmail.Text = GridSupplier.Item(5, i).Value</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonHapus.Enabled = <span style="color:blue;">True</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span>ButtonUpdate.Enabled = <span style="color:blue;">True</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"><span> </span><span style="color:blue;">End</span> <span style="color:blue;">Sub</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">End</span><span style="font-size:10pt;font-family:&#34;"> <span style="color:blue;">Class</span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&#34;">Sampai disini dulu artikel tentang </span><span style="font-size:11pt;font-family:&#34;">Program input dan edit data dengan VB.NET 2005 dan SQL Server 2005, semoga menjadi ilmu yang bermanfaat. Saya sangat mengharapkan saran komentar anda, sehingga membuat ilmu pengetahuan berkembang, Salam programming</span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:&#34;">@pri</span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:&#34;"> </span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:&#34;">Penghujung Juli 2008, Sarijadi, </span><span style="font-size:11pt;font-family:&#34;">Bandung</span></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[ADO.Net]]></title>
<link>http://programmingindexcards.wordpress.com/?p=21</link>
<pubDate>Wed, 23 Jul 2008 13:24:06 +0000</pubDate>
<dc:creator>apcig</dc:creator>
<guid>http://programmingindexcards.wordpress.com/?p=21</guid>
<description><![CDATA[DataSet vs. DataReader1
1. DataReaders have less overhead than DataSets and are more efficient.
2. D]]></description>
<content:encoded><![CDATA[<p><strong>DataSet vs. DataReader</strong><sup>1</sup></p>
<p>1. DataReaders have less overhead than DataSets and are more efficient.<br />
2. DataReaders can be databound (i.e. to a DataGrid).<br />
3. Iterated once through</p>
<p>but</p>
<p>1. DataSets are <em>disconnected. </em>They are like disconnected models of the database.<br />
2. DataSets can be made into Session objects or files, for persistence<br />
3. DataSets can provide access to more than one table and table relationships<br />
4. DataSets can be bound to multiple controls<br />
5. Reiterated through multiple times.<br />
5. You can jump to a particular record or go backwards through a DataSet.<br />
6. Ability to name your table</p>
<p><sup>1</sup> <a href="http://jcf-mls.blogspot.com/2007/07/dataset-vs-datareader.html">My Library Syndication</a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Implementing a 3-Tier architecture with C# - Part 5 ]]></title>
<link>http://aspguy.wordpress.com/?p=55</link>
<pubDate>Tue, 22 Jul 2008 11:06:55 +0000</pubDate>
<dc:creator>aspguy</dc:creator>
<guid>http://aspguy.wordpress.com/?p=55</guid>
<description><![CDATA[Hi back,
In this post we will finalize the implementation of our 3-tier asp.net architecture, by dev]]></description>
<content:encoded><![CDATA[<p style="text-align:justify;">Hi back,</p>
<p style="text-align:justify;">In this post we will finalize the implementation of our 3-tier asp.net architecture, by developing a Web-based presentation layer.</p>
<p style="text-align:justify;">So far, we have developed the data access and business layers. The implementation of UI, consists of methods and approaches for handling business and crud operations thorough a Web UI. In fact, there are several ways to present business objects and reflect the changes back to data base. Like:</p>
<ol style="text-align:justify;">
<li>Binding controls (i.e. GridView) directly to DataTables coming from business classes (i.e. by FetchAll method)</li>
<li>Binding controls (.e. GridView) to business classes using an IDataSource, like ObjectDataSouce control.</li>
<li>Mixing up the above methods.</li>
</ol>
<p style="text-align:justify;">If you opt the first option, you need to handle sorting and paging manually. It means that you have to write code for PageIndexChanged and Sorted methods. This might take several minutes for you to handle every details and make your development process too long and not productive.</p>
<p style="text-align:justify;">A better approach is using ObjectDataSource. For using it, we have to prepare our business classes first. ObjectDataSoruce works with classes that DataObject attribute has been applied to them. Thus, open your business class (i.e. PersonBiz.cs), and apply DataObject attribute on it:</p>
<p style="text-align:justify;"><span style="color:#800000;">[DataObject]</span></p>
<p style="text-align:justify;"><span style="color:#800000;">public class PersonBiz<br />
{ ...</span></p>
<p style="text-align:justify;">Then we might specify four methods for doing Select/Insert/Update/Delete operations. However, I personally prefer to use Select method only and do the other operations manually. My reason is that, if I declare a method for Insert/Update methods, I will have to use GridView's (or similar controls) editing features and have to pass a lot of params to the Insert/Update methods. and I do not like it! :-)</p>
<p style="text-align:justify;">Anyway, to mark a method as a Select method, we have to apply DataObjectMethod attribute on it. This attribute takes a parameter indicating which kind of method is it. For example, a select method can be declared like this:<br />
<span style="color:#800000;"> [DataObjectMethod(DataObjectMethodType.Select)]<br />
public DataTable FetchAll(...</span></p>
<p style="text-align:justify;">If you are intended to use ObjectDataSource, your Select method must have a return value of type IENumerable, and preferably, it would better return a DataTable or DataView.Thus, FetchAll method returns  a DataTable. It also has two parameters as follows:</p>
<p style="text-align:justify;"><span style="color:#800000;"> [DataObjectMethod(DataObjectMethodType.Select)]<br />
public DataTable FetchAll(int startRowIndex, int maximumRows)<br />
{<br />
PersonEntity entity = new PersonEntity();<br />
innerDAL.Fill(entity, startRowIndex, maximumRows);<br />
return entity;<br />
}</span></p>
<p style="text-align:justify;">As you see, t<span style="color:#000000;">he </span><span style="color:#000000;">startRowIndex and </span><span style="color:#000000;">maximumRows are used for paging. If you do not wish to manage paging, you may omit these two arguments. </span></p>
<p style="text-align:justify;">To bind your UI control (i.e. GridView) to this method, put an ObjectDataSource on your web form. Then, choose Configure DataSource from it's smart tag.  The Configure Data Source window will open:</p>
<p style="text-align:justify;"><a href="http://aspguy.files.wordpress.com/2008/07/cds.jpg"><img class="alignnone size-medium wp-image-56" src="http://aspguy.wordpress.com/files/2008/07/cds.jpg?w=300" alt="" width="300" height="232" /></a></p>
<p style="text-align:justify;">Check the "Show only data components" and open the drop down list beside it. If nothing is seen, you have to build the BusinessLayer.Dll and put it in your website's Bin folder.</p>
<p style="text-align:justify;">Select your business class and click Next. At the next step, you have to specify which methods are used for Select, Insert, Update and Delete operations. The following image is an example :</p>
<p style="text-align:justify;"><a href="http://aspguy.files.wordpress.com/2008/07/cds2.jpg"><img class="alignnone size-medium wp-image-57" src="http://aspguy.wordpress.com/files/2008/07/cds2.jpg?w=300" alt="" width="300" height="233" /></a></p>
<p style="text-align:justify;">After choosing all your methods, click Finish to close this dialog. If you are going to let the ObjectDataSource handle the paging operation, go to your page's source code, find the code of GridView control and remove the SelectParameters. This is necessary because startRowIndex and maximumRows will be provided by ObjectDataSource control. If you do not remove them, you will get an error message.</p>
<p style="text-align:justify;">In order to activate paging in ObejctDataSource, you have to set its EnablePaging property to True. you also have to set the AllowPaging property of your GridView control to true. In order for ObjectDataSource to do paging operation correctly, we have to tell it how many records are in database. Therefore, there must be a public method in our business class that return the total number of rows in DB. What we need is to assign it's name to SelectCountMethod property of ObjectDataSource. You do not need to flag this property with an attribute:</p>
<p style="text-align:justify;"><span style="color:#800000;">public int GetTotalRecordCount()<br />
{<br />
return innerDAL.GetTotalRecordCount();<br />
}</span></p>
<p style="text-align:justify;"><span style="color:#800000;"><span style="color:#000000;">Notice that if you are filtering the results of your SelectMethod, for example by passing a filter string to it, you have to perform the same filter on the result of </span></span>SelectCountMethod.</p>
<p style="text-align:justify;">Now build and run your website. you will see that the data is being shown and the grid supports sorting and paging very well. To ensure that paging is working correctly, run Microsoft Sql Server Profiler, and check to see if the Select SQL statement has correct startRowIndex and maximumRowCount values.</p>
<p style="text-align:justify;">To insert a new record, you may create a new entity (i.e. PersonEntity) , fill it and save it to DB.</p>
<p style="text-align:justify;">To update a record, retrieve the record from database using it's Primary Key, edit it and save it back to db.</p>
<p style="text-align:justify;">To delete a record, perform a delete operation on database using the records PK.</p>
<p style="text-align:justify;">But how to obtain the record's Primary Key? You may save it somewhere in UI when the UI control is getting bound. To do this, I usually write such a code in RowDataBound event :</p>
<p style="text-align:justify;"><span style="color:#800000;">if (e.Row.RowType == DataControlRowType.DataRow)<br />
{<br />
int Serial = DataBinder.Eval(e.Row.DataItem, "Serial");<br />
e.Row.Cells[0].Attributes.Add("Serial", Serial.ToString());<br />
}</span></p>
<p style="text-align:justify;"><span style="color:#000000;">In the above code, if the row being bound is a data row (not footer or header), we get the value of "Serial" column and store it in the 1st cell of the current row. Notice that whatever toy add yo .Attributes collection will be available to the rendered html page. Thus, never save passwords or other sort of crucial data with this method.</span></p>
<p style="text-align:justify;">Now, for each row, you have the Primary Key value. Therefore, we may perform update and delete operations easily. Not keeping the whole data in memory (or in ViewState), increases the access to data base, but reduces the usage of server's resources. However, it is up to you and your project's conditions to decide that method should be used.</p>
<p style="text-align:justify;">You may download a full example of this implementation <a href="http://www.filedony.com/fileupload/download.php?file=ae3e6d4a298317e59566afeb4a0a4012" target="_blank">HERE</a>. Please note that the file is password protected and it's password is : aspguy.wordpress.com</p>
<p style="text-align:justify;">Bye for now..</p>
<p style="text-align:justify;">
]]></content:encoded>
</item>
<item>
<title><![CDATA[Generic DataReader]]></title>
<link>http://banditoplus.wordpress.com/?p=14</link>
<pubDate>Mon, 21 Jul 2008 21:33:12 +0000</pubDate>
<dc:creator>banditoplus</dc:creator>
<guid>http://banditoplus.wordpress.com/?p=14</guid>
<description><![CDATA[Today I realised working with IDataReader can be a real pain. First of all you can&#8217;t actually ]]></description>
<content:encoded><![CDATA[<p>Today I realised working with <em>IDataReader</em> can be a real pain. First of all you can't actually check if a column actually exists before accessing a field. You simply get an <em>IndexOutOfRange</em> Exception. You can't even test if its null.</p>
<p><strong>No Exception</strong></p>
<p>One way to solve this problem is to use the property <em>FieldCount</em> and method <em>GetName</em>.</p>
<p><code>IDataReader reader = <em>[MyDataSource]</em>;<br />
List&#60;string&#62; header = new List&#60;string&#62;( );<br />
for (int i = 0; i &#60; reader.FieldCount; ++i)<br />
{<br />
&#160;&#160;&#160;header.Add(reader.GetName(i));<br />
}</code></p>
<p>Now you can check if the column exists by looking for it in the list.<br />
<code>if( header.Contains( "MyColumnName" ))<br />
{ ... }</code></p>
<p><strong>DBNull != null</strong></p>
<p>The next problem is that the return value might be DBNull. Unluckily DBNull isn't null, so you can't use the practical ?? operator. So this will not work:</p>
<p><code>int x = (int)(reader["MyInt"] ?? 0);</code></p>
<p>What would be possible is this:</p>
<p><code>int x = reader.IsDBNull( reader.GetOrdinal( "MyInt" ) )  ?  (int) reader["MyInt"] : 0;</code></p>
<p>But that's just awful.</p>
<p><strong>Generic Method</strong></p>
<p>OK, my first attempt to solve both problems was a simple utility method.</p>
<p><code>protected T GetValue&#60;T&#62;(IDataReader reader, List&#60;string&#62; header, string fieldname)<br />
{<br />
&#160;T result = default(T);<br />
&#160;if (header.Contains(fieldname))<br />
&#160;{<br />
&#160;&#160;if (reader[fieldname] != Convert.DBNull)<br />
&#160;&#160;{<br />
&#160;&#160;&#160;result = (T)reader[fieldname];<br />
&#160;&#160;}<br />
&#160;}<br />
&#160;return result;<br />
}</code></p>
<p>This generic method gets the current reader instance, the header list from before and the name of the field as parameter. T is the column type. default(T) sets the default value of the type, so null for objects and 0 (int) for value types. We then run both tests and finally cast the value.<br />
A method call would look something like this:</p>
<p><code>int x = GetValue&#60;int&#62;(reader, header, "MyInt");</code></p>
<p>That does actually work, but I hate the idea of sending the reader and header in each call. So the next step is wrapping everything up in a class.</p>
<p><strong>Generice DataReader Class</strong></p>
<p><code>public class GenericDataReader<br />
{<br />
&#160;private IDataReader reader;<br />
&#160;private List&#60;string&#62; header = new List&#60;string&#62;();</p>
<p>&#160;public GenericDataReader(IDataReader reader)<br />
&#160;{<br />
&#160;&#160;this.reader = reader;<br />
&#160;&#160;for (int i = 0; i &#60; reader.FieldCount; ++i)<br />
&#160;&#160;{<br />
&#160;&#160;&#160;header.Add(reader.GetName(i));<br />
&#160;&#160;}<br />
&#160;}</p>
<p>&#160;public bool Read()<br />
&#160;{<br />
&#160;&#160;if (reader == null)<br />
&#160;&#160;{<br />
&#160;&#160;&#160;return false;<br />
&#160;&#160;}<br />
&#160;&#160;return reader.Read();<br />
&#160;}</p>
<p>&#160;public void Close()<br />
&#160;{<br />
&#160;&#160;reader.Close();<br />
&#160;}</p>
<p>&#160;public T Value&#60;T&#62;(string fieldname)<br />
&#160;{<br />
&#160;&#160;T result = default(T);<br />
&#160;&#160;if (header.Contains(fieldname))<br />
&#160;&#160;{<br />
&#160;&#160;&#160;if (reader[fieldname] != Convert.DBNull)<br />
&#160;&#160;&#160;{<br />
&#160;&#160;&#160;&#160;result = (T)reader[fieldname];<br />
&#160;&#160;&#160;}<br />
&#160;&#160;}<br />
&#160;&#160;return result;<br />
&#160;}</p>
<p>&#160;public object this[int i]<br />
&#160;{<br />
&#160;&#160;get{ return reader[i]; }<br />
&#160;}<br />
}</code></p>
<p>The class is fairly simple and wraps the IDataReader functionality quite nicely. As you can see the Read() method returns false if the IDataReader is null. One thing less to worry about when looping through the data. The indexer at the end of the class allows you to access the reader directly if necessary.</p>
<p>Last example for today:</p>
<p><code>IDataReader reader = <em>[MyDataSource]</em>;<br />
GenericDataReader g = new GenericDataReader(reader);<br />
while(g.Read( ))<br />
{<br />
&#160;int x = g.GetValue&#60;int&#62;("MyInt");<br />
}<br />
g.Close( );</code></p>
<p>Now IDataReader should be a little more tame.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Implementing a 3-Tier architecture with C# - Part 4]]></title>
<link>http://aspguy.wordpress.com/?p=45</link>
<pubDate>Fri, 18 Jul 2008 10:42:00 +0000</pubDate>
<dc:creator>aspguy</dc:creator>
<guid>http://aspguy.wordpress.com/?p=45</guid>
<description><![CDATA[Up to now, we have finished implementing the data access layer. However, we can reduce the dependenc]]></description>
<content:encoded><![CDATA[<p style="text-align:justify;">Up to now, we have finished implementing the data access layer. However, we can reduce the dependency between the deriver DAL classes and Web.config file. As you remember, we have specified the DB provider name in Web.config file so that DAL classes must have access to this file to read the provider name. Another method to specify the provider type is using custom attributes.</p>
<p style="text-align:justify;">Firstly, in the DataAccessLayerBase namespace, we declare a public <span style="color:#0000ff;">enum </span>type named ProviderType:</p>
<p style="text-align:justify;"><span style="color:#800000;">public enum ProviderType<br />
{<br />
SqlServer,<br />
Odbc,<br />
OleDb<br />
}</span></p>
<p style="text-align:justify;">We also remove the ProviderName property from DALHelper class, and instead, add a new internal method, as bellow, to get a string representation of each ProviderType member:</p>
<p style="text-align:justify;"><span style="color:#800000;">internal static string GetProviderTypeName(ProviderType providerType)<br />
{<br />
switch (providerType)<br />
{<br />
case ProviderType.SqlServer: return "System.Data.SqlClient";<br />
case ProviderType.Odbc: return "System.Data.Odbc";<br />
case ProviderType.OleDb: return "System.Data.OleDb";<br />
default: return "System.Data.SqlClient";<br />
}<br />
}</span><br />
The custom attribute we need for specifying the provider type, must have a public property of type ProviderType. We also add a constructor, with a positional parameter of type ProviderType, to our custom attribute class:</p>
<p style="text-align:justify;"><span style="color:#800000;">[AttributeUsage(AttributeTargets.Class)]<br />
public sealed class DbProviderTypeAttribute : Attribute<br />
{<br />
public ProviderType PrType<br />
{<br />
set;<br />
get;<br />
}<br />
}</span></p>
<p style="text-align:justify;">The AttributeUsage attribute indicates that this custom attribute can be applied to classes only.</p>
<p style="text-align:justify;">To make this attribute effective, we need to alter the base DAL class's constructor as bellow:</p>
<p style="text-align:justify;">first we must check to see if the DbProviderTypeAttribute attribute has been applied to the derived DAL class:</p>
<p style="text-align:justify;"><span style="color:#800000;">if (!this.GetType().IsDefined(typeof(DbProviderTypeAttribute), false))<br />
throw new System.Exception("DbProviderTypeAttribute must be applied to DAL class");</span></p>
<p style="text-align:justify;">The above code examines the existence of DbProviderTypeAttribute and throws an exception of it does not exist.</p>
<p style="text-align:justify;">Then, the following piece of code, extracts the instance of DbProviderTypeAttribute from the class's metadata, and uses the value of it's PrType property to set the ProviderName :</p>
<p style="text-align:justify;"><span style="color:#800000;">List&#60;object&#62; t = this.GetType().GetCustomAttributes(typeof(DbProviderTypeAttribute), false).ToList();<br />
DbProviderTypeAttribute Provider = t[0] as DbProviderTypeAttribute;<br />
ProviderName = DALHelper.GetProviderTypeName(Provider.PrType);<br />
_ProviderFactory = DbProviderFactories.GetFactory(ProviderName);</span></p>
<p style="text-align:justify;">That's it. This way we have reduced the coupling between our UI (web.config file) and the DAL class. When developing a derived DAL class, we have to apply DbProviderType attribute to it:</p>
<p style="text-align:justify;"><span style="color:#800000;"> [DbProviderType(PrType=ProviderType.SqlServer)]<br />
public class PersonDAL  : DALBase<br />
{ ...</span></p>
<h3 style="text-align:justify;">Implementing the business classes</h3>
<p style="text-align:justify;">The implementation of business classes are fairly easy. A business class is a bridge between the presentation layer and the data access layer, perform business checks, controls concurrencies and even might control the business transactions.</p>
<p style="text-align:justify;">The business classes can be either static or instance classes. Each business method can create one or more instances of the required DAL classes. However, since each DAL class has it's own connection object (innerConnection property), system transactions would better be controlled in business methods. This may even solve the issue that is raised when a layered architecture needs to control both business and system transactions.</p>
<p style="text-align:justify;">The easiest way to control the transactions, is using System.Transaction name space and TransactionScope class. The illustration of TransactionScope requires an indipendent post, but for now, lets say that transaction begins when an instance of TransactionScope class is created and it is commited when the .Complete() method is called:</p>
<p style="text-align:justify;"><span style="color:#800000;">using (TransactionScope scope = new TransactionScope())</span></p>
<p style="text-align:justify;"><span style="color:#800000;">{</span></p>
<p style="text-align:justify;"><span style="color:#800000;">.....<br />
</span></p>
<p style="text-align:justify;"><span style="color:#800000;">scope.Complete();</span></p>
<p style="text-align:justify;"><span style="color:#800000;">}</span></p>
<p style="text-align:justify;">if an exception is thrown, the transaction will roll back :</p>
<p style="text-align:justify;"><span style="color:#800000;">using (TransactionScope scope = new TransactionScope())</span></p>
<p style="text-align:justify;"><span style="color:#800000;">{</span></p>
<p style="text-align:justify;"><span style="color:#800000;">PersonDAL PDAL= new PersonDAL();</span></p>
<p style="text-align:justify;"><span style="color:#800000;">....</span></p>
<p style="text-align:justify;"><span style="color:#800000;">ChildDAL CDAL= new ChildDAL();</span></p>
<p style="text-align:justify;"><span style="color:#800000;">...</span></p>
<p style="text-align:justify;"><span style="color:#800000;">PDAL.Update(personDT);</span></p>
<p style="text-align:justify;"><span style="color:#800000;">CDAL.Update(childDT);</span></p>
<p style="text-align:justify;"><span style="color:#800000;">scope.Complete();</span></p>
<p style="text-align:justify;"><span style="color:#800000;">}</span></p>
<p style="text-align:justify;">Note that MSDTC service must be running on the server machine.</p>
<p style="text-align:justify;">so far, the definition of business classes requires no additional settings. however, when developing the presentaion layer, we will come back and make some minor changes to make our bisuness classes compatible with UI components.</p>
<p style="text-align:justify;">A sample business class might look like this:</p>
<p style="text-align:justify;"><span style="color:#800000;"> public class PersonBiz<br />
{</span></p>
<p style="text-align:justify;"><span style="color:#800000;"> private PersonDAL innerDAL = new PersonDAL();<br />
public DataTable FetchAll(int startRowIndex, int maximumRows)<br />
{<br />
PersonEntity entity = new PersonEntity();<br />
innerDAL.Fill(entity, startRowIndex, maximumRows);<br />
return entity;<br />
}</span></p>
<p><span style="color:#800000;">public void Update(System.Data.DataTable table)<br />
{<br />
// validate fields/perform business checks and throw an exception if a criteria is not met<br />
innerDAL.Update(table);<br />
}<br />
:</span></p>
<p style="text-align:justify;"><span style="color:#800000;"> :</span></p>
<p style="text-align:justify;"><span style="color:#800000;"> }</span></p>
<p style="text-align:justify;">
]]></content:encoded>
</item>
<item>
<title><![CDATA[Linq to Sql e Ado.Net a confronto]]></title>
<link>http://pythonyan.wordpress.com/?p=238</link>
<pubDate>Wed, 16 Jul 2008 09:44:55 +0000</pubDate>
<dc:creator>pythonyan</dc:creator>
<guid>http://pythonyan.wordpress.com/?p=238</guid>
<description><![CDATA[Come postato da Minerva al seguente link è possibile leggere alcune differenze tra l&#8217;approcci]]></description>
<content:encoded><![CDATA[<p>Come postato da Minerva al seguente <a href="http://blogs.msdn.com/wriju/archive/2008/07/14/linq-to-sql-vs-ado-net-a-comparison.aspx">link </a>è possibile leggere alcune differenze tra l'approccio Linq To Sql e Ado.Net.Molto interessante e .. istruttivo.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Implementing a 3-Tier architecture with C# - Part 3]]></title>
<link>http://aspguy.wordpress.com/?p=35</link>
<pubDate>Tue, 15 Jul 2008 19:42:59 +0000</pubDate>
<dc:creator>aspguy</dc:creator>
<guid>http://aspguy.wordpress.com/?p=35</guid>
<description><![CDATA[The Fill method we have developed so far, executes the Select command on the underlaying server and ]]></description>
<content:encoded><![CDATA[<p style="text-align:justify;">The Fill method we have developed so far, executes the Select command on the underlaying server and picks up <span style="color:#800000;">RowCount </span>records from <span style="color:#800000;">startRowIndex </span>position. For example, if <span style="color:#ff0000;">Select * from Person</span> returnS 20 rows, and <span style="color:#800000;">startRowIndex </span>is 0, only the first <span style="color:#800000;">RowCount </span>records will be fetched. This means that the complete result set will be generated on server and will be fetched into an IDataReader, but ADO.NET transmits only <span style="color:#800000;">RowCount </span>number of records into the DataTable. If the results are too many, that will not be helpful that much, so we have to do something about it.</p>
<p style="text-align:justify;">For doing this, we may define the Fill method virtual and each DAL class may override it to fetch records based on startRowIndex and RowCount from the data base. The 2nd way is to assume that every <span style="color:#800000;">SelectCommand </span>has two paramerers names <span style="color:#800000;">startRowIndex </span>and <span style="color:#800000;">RowCount</span>! This means that we always must supply two <span style="color:#0000ff;">int </span>parameters to Fill method. I propose you to have several overloaded Fill methods to use a proper one in different occasions.</p>
<p style="text-align:justify;">Anyway, if we suppose that every SelectCommand executes a stored procedure having two int parameters, we might change the Fill method (or develop an overloaded one) this way:</p>
<p><span style="color:#800000;">public void Fill(DataTable table, int startRowIndex, int RowCount)<br />
{<br />
DbParameter p;<br />
innerAdapter.SelectCommand.Parameters.Clear();</span></p>
<p><span style="color:#800000;">p = ProviderFactory.CreateParameter();<br />
p.ParameterName = "StartIndex";<br />
p.Value = startRowIndex;<br />
innerAdapter.SelectCommand.Parameters.Add(p);</span></p>
<p><span style="color:#800000;">p = ProviderFactory.CreateParameter();<br />
p.ParameterName = "RowCount";<br />
p.Value = RowCount;<br />
innerAdapter.SelectCommand.Parameters.Add(p);<br />
if (table.Rows.Count &#62; 0)<br />
table.Rows.Clear();<br />
innerAdapter.Fill(table);<br />
}</span></p>
<p style="text-align:justify;">This Fill method adds two parameters to SelectCommand property of the innerAdapter, fills the DataTable by calling the innerAdapter.Fill method. Notice that we must clear up the DataTable because the innerAdapter.Fill method will append new records to the DataTable if any records exists in it.</p>
<p style="text-align:justify;">But how to implement the paging? The answer might differ fro different data bases. However, I will provide a simple method for SQL Server 2005. SQL Server 2005 provides Ranking funtions, i.e. Row_Number() funtion, so that we may easily rank the resulting records of each table. For more information about Row_number function, please check out the SQL Server 2005 Books Online or MSDN.</p>
<p style="text-align:justify;">Anyway, for our sample database, I have written a stored procedure named FetchAllPerson which has two int parameters, called @StartIndex and @RowCount:</p>
<p style="text-align:justify;"><span style="color:#800080;">create procedure FetchAllPerson<br />
@StartIndex int,<br />
@RowCount int<br />
As</span></p>
<p><span style="color:#800080;">with NoFilterRecords<br />
as<br />
(<br />
Select Row_Number() over (order by Serial) as RIndex , Serial, FirstName, LastName from Person<br />
)<br />
Select * from NoFilterRecords where RIndex&#62;=@StartIndex and RIndex &#60;@StartIndex+@RowCount<br />
order by 1<br />
Go</span></p>
<p style="text-align:justify;"><span style="color:#000000;">This proced</span>ure first ranks all records, then fetch only those records positioned in the specific range. Therefore, the innerAdapter.SelectCommand.CommandType must be set to CommandType .StoredProcedure .</p>
<p style="text-align:justify;"><span style="color:#993300;">innerAdapter.SelectCommand.CommandText = "FetchAllPerson";<br />
innerAdapter.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;</span></p>
<h3>Working with identity fields</h3>
<p>The value of Identity fields is generated automatically. Therefore, a new row in a DataTable, may not have a value for its Identity fields or their value may not be identical to the mapping record in database after the record is inserted. Thus, we have to reflect the new value of  Identity fields to the related row inside the DataTable. For doing this, add a Select statement to the end of Insert statements and seperate them with a semi colon  :</p>
<p><span style="color:#993300;">inne</span><span style="color:#ff0000;"><span style="color:#993300;">rAdapter.InsertCommand.CommandText = "Insert into Person (Serial, FirstName, LastName) \n" +<br />
"Values (@Serial, @FirstName, @LastName); \n" +<br />
"Select * from Person where Serial = SCOPE_IDENTITY()";</span></span></p>
<p>The Select statement will fetch the new record from database and reflect any changes to the inserted row. To make this method work, we must set the UpdatedRowSource property to  FirstReturnedRecord:</p>
<p>innerAdapter.InsertCommand.UpdatedRowSource = System.Data.UpdateRowSource.FirstReturnedRecord;</p>
<p>This may be done in the base DAL class. This setting will fetch one record and will synchronize the inserted row with the data base. The SCOPE_IDENTITY() funtion returns the last identity value assigned to a field. This works in SQL SERVER only and you must perform a similar task for other data bases.</p>
<p>Ok this is all about the Data Access Layer. We will discuss about the business layer on the next post.</p>
<p style="text-align:justify;">
<p style="text-align:justify;">
<p style="text-align:justify;">
]]></content:encoded>
</item>
<item>
<title><![CDATA[Check log every 5 min in C#]]></title>
<link>http://scriptforall.wordpress.com/?p=27</link>
<pubDate>Tue, 15 Jul 2008 11:42:54 +0000</pubDate>
<dc:creator>kostland</dc:creator>
<guid>http://scriptforall.wordpress.com/?p=27</guid>
<description><![CDATA[where timerticlickvoid is the click of the timer&#8230;.
public void timertickvoid()
{
// Set the ti]]></description>
<content:encoded><![CDATA[<p>where timerticlickvoid is the click of the timer....</p>
<p>public void timertickvoid()<br />
{<br />
// Set the timer interval to 5 minutes<br />
timerCheck.Interval = (int)(5 * 1000 * 60);</p>
<p>FileStream fs = File.OpenRead("timer.log");<br />
StreamReader sr = new StreamReader(fs);<br />
string myInput = sr.ReadToEnd();<br />
sr.Close();<br />
fs.Close();</p>
<p>DateTime dtFile = Convert.ToDateTime(myInput);</p>
<p>DateTime dt2 = DateTime.Now;</p>
<p>TimeSpan span = dt2.Subtract(dtFile);<br />
int dif = span.Days*60*24 + span.Hours*60+span.Minutes;<br />
if (dif &#62; 5)//&#62;60<br />
{<br />
RunRoutines();<br />
}</p>
<p>}</p>
]]></co