This is a pretty little thing but it may cause sometimes a lot of problem when you are implementing the email function. Suppose you are using System.Net.Mail namespace for implementing email functionality.So code is:
using System.Net.Mail;
MailMessage msg=new MailMessage("from@gmail.com","to@gmail.com");
msg.CC="masudcseku@gmail.com"; /*Error*/
msg.CC.Add("masudcseku@gmail.com");/*correct*/
msg.bcc="masud_mnthk@yahoo.com"; /*Error*/
msg.bcc.Add("masud_mnthk@yahoo.com");/*correct*/
This is a pretty little thing huh!...but often this will be useful.
**************************************
Masud(7.25.2009)
Friday, July 24, 2009
Issuing a javascript object by ASP.NET at load time
This is a nice feature ASP.NET provides that ASP.NET is providing a javascript object populated with data which can be used by client-side script very effectively. Let see this step by step.
Steps:
1. Suppose in ASP.NET you are using some variable (ex:testaskingprices) having some value. Now you want to transfer this value to access by the client-side code. So then you have execute this code in Page_Load event of page
this.ClientScript.RegisterArrayDeclaration("myAskPriceList", testaskingprices);
where
testaskingprices=the ASP.NET variable
myAskPriceList=the javascript variable issued for use
**************************************
Masud (25.7.9)
Steps:
1. Suppose in ASP.NET you are using some variable (ex:testaskingprices) having some value. Now you want to transfer this value to access by the client-side code. So then you have execute this code in Page_Load event of page
this.ClientScript.RegisterArrayDeclaration("myAskPriceList", testaskingprices);
where
testaskingprices=the ASP.NET variable
myAskPriceList=the javascript variable issued for use
**************************************
Masud (25.7.9)
I am living bugs life
Ohh...I cant sleep at night. I found my legs and hands are punctured at different places and I was surprised this could be. Every night I keep up myself up to 6.00 AM. when it is about to morning I get sleep being tired. To my utter surprise I found that I am living with bugs...(charpoka). Wooh...this fucking insect is killing me. I writing this blog also keeping myself awake and often I am killing them.....I need to change this mess.
Masud
Masud
I am living bugs life
Ohh...I cant sleep at night. I found my legs and hands are punctured at different places and I was surprised this could be. Every night I keep up myself up to 6.00 AM. when it is about to morning I get sleep being tired. To my utter surprise I found that I am living with bugs...(charpoka). Wooh...this fucking insect is killing me. I writing this blog also keeping myself awake and often I am killing them.....I need to change this mess.
Masud
Masud
Friday, July 17, 2009
Getting some hand over web technology
After serving 2-3 months in my company I found some changes in my thought regarding my works and I found that really professionalism needs an environment to develop. I, who could not develop an entire web site properly during my university years properly...that guy is about to complete a professional website within few days.This time I have found some ideas. Lets code it down.
1. Learn controls of AJAX and Silver light ASAP..download toolkit. Download IDE if needed...
2. Download Jquery library and execute the controls and enhance to a professional level
3. Have a good concept on WPF,WCF...
4. Learn different application of XML....
These are the ideas so far I have got...
masud
(17.7.9)
1. Learn controls of AJAX and Silver light ASAP..download toolkit. Download IDE if needed...
2. Download Jquery library and execute the controls and enhance to a professional level
3. Have a good concept on WPF,WCF...
4. Learn different application of XML....
These are the ideas so far I have got...
masud
(17.7.9)
Getting some hand over web technology
After serving 2-3 months in my company I found some changes in my thought regarding my works and I found that really professionalism needs an environment to develop. I, who could not develop an entire web site properly during my university years properly...that guy is about to complete a professional website within few days.This time I have found some ideas. Lets code it down.
1. Learn controls of AJAX and Silver light ASAP..download toolkit. Download IDE if needed...
2. Download Jquery library and execute the controls and enhance to a professional level
3. Have a good concept on WPF,WCF...
4. Learn different application of XML....
These are the ideas so far I have got...
masud
(17.7.9)
1. Learn controls of AJAX and Silver light ASAP..download toolkit. Download IDE if needed...
2. Download Jquery library and execute the controls and enhance to a professional level
3. Have a good concept on WPF,WCF...
4. Learn different application of XML....
These are the ideas so far I have got...
masud
(17.7.9)
Difference between ametuership & professionalism
There are of course some differences between these two which I come to realize after 2 or 3 months of my job career. let me point out some things:
1. professionalism demands pure concentration
2. professionalism demands more broad outlook towards work, customer-needs etc.
3. professionalism demands more dedication & responsibility and accountability
4. it demands aspiration for learning, higher position.
5. it demands expected level of contribution to the company
..............................................................
These are the things I have got so far.
thanks.
masud (17.7.9)
1. professionalism demands pure concentration
2. professionalism demands more broad outlook towards work, customer-needs etc.
3. professionalism demands more dedication & responsibility and accountability
4. it demands aspiration for learning, higher position.
5. it demands expected level of contribution to the company
..............................................................
These are the things I have got so far.
thanks.
masud (17.7.9)
Difference between ametuership & professionalism
There are of course some differences between these two which I come to realize after 2 or 3 months of my job career. let me point out some things:
1. professionalism demands pure concentration
2. professionalism demands more broad outlook towards work, customer-needs etc.
3. professionalism demands more dedication & responsibility and accountability
4. it demands aspiration for learning, higher position.
5. it demands expected level of contribution to the company
..............................................................
These are the things I have got so far.
thanks.
masud (17.7.9)
1. professionalism demands pure concentration
2. professionalism demands more broad outlook towards work, customer-needs etc.
3. professionalism demands more dedication & responsibility and accountability
4. it demands aspiration for learning, higher position.
5. it demands expected level of contribution to the company
..............................................................
These are the things I have got so far.
thanks.
masud (17.7.9)
Tuesday, July 14, 2009
Allowing paging in Gridview when datasource is not predefined
Suppose you are not setting predefined data source means you are not using sqldatasource as the data source then this article is helpful for enabling the paging option. Suppose you will determine data source at run-time means you are using SqldataAdapter then u are welcome:
In the html code of Gridview you have to set AllowPaging="true"
Here is the code for handling paging manualy:
protected void TestGV_pageIndexChanging(object sender, GridViewPageEvent e)
{
TestGV.pageIndex=e.NewPageIndex;
TestGV.dataBind();
}
Here we see page index is updated as the index of page changes. By default page size=10 however it can be changed in the html code of Gridview.
Thats for today
Masud (15.7.9)
In the html code of Gridview you have to set AllowPaging="true"
Here is the code for handling paging manualy:
protected void TestGV_pageIndexChanging(object sender, GridViewPageEvent e)
{
TestGV.pageIndex=e.NewPageIndex;
TestGV.dataBind();
}
Here we see page index is updated as the index of page changes. By default page size=10 however it can be changed in the html code of Gridview.
Thats for today
Masud (15.7.9)
Removing underline from a hyper link
This is a nice thing and expected attribute often. This time we have to take the help of Cascading Style sheet. Here we should follow 2 steps:
1. define a class in css file
2. apply the class to the control
Lets discuss:
1.class hyp in css file:
.hyp
{
font-weight:bold;
display:run-in;
text-decoration:none;
cursor:pointer;
}
Here text-decoration is set to none therefore underline will not be shown.
2. using class to the control:
<asp:HyperLink ID="mylink" runat="server" CssClass="hyp" NavigateUrl="mypage.aspx">
Go to my page
</asp:HyperLink>
Here we see that css class is set to the control but one thing must be done while using the css class. Css file must be linked to the page in head section. Here is that code
<link href="default.css" type="text/css" rel="Stylesheet"/>
I think this will be helpful.
thanks.
Masud (15.7.9)
1. define a class in css file
2. apply the class to the control
Lets discuss:
1.class hyp in css file:
.hyp
{
font-weight:bold;
display:run-in;
text-decoration:none;
cursor:pointer;
}
Here text-decoration is set to none therefore underline will not be shown.
2. using class to the control:
<asp:HyperLink ID="mylink" runat="server" CssClass="hyp" NavigateUrl="mypage.aspx">
Go to my page
</asp:HyperLink>
Here we see that css class is set to the control but one thing must be done while using the css class. Css file must be linked to the page in head section. Here is that code
<link href="default.css" type="text/css" rel="Stylesheet"/>
I think this will be helpful.
thanks.
Masud (15.7.9)
Formatting data in Gridview cell
This is an important thing u need when working with grid-view. Suppose u want to format the numerical data in currency form or date form then you have to do a little trick.
Suppose your column name is
"Amount" should be shown as currency (ex: $100)
"PaymentDate" should be shown as date (ex:7/12/2009), generally SQL 2005 will show it as (7/12/2009 12.00 AM) which is a bad format.
so lets check it out. Suppose we are using TemplatedField in GridView and as field we are using labels ..so the code like this.
<asp:GridView ID="TestGV" runat="server">
<Columns>
<asp:TemplatedField>
<ItemTemplate>
<asp:Label ID="CurrencyLabel" runat="server" Text='<%#String.Format("{0:c}",Eval("Amount"))%>' > </asp:Label>
</ItemTemplate>
</asp:TemplatedField>
<asp:TemplatedField>
<ItemTemplate>
<asp:Label ID="PaymentDateLabel" runat="server" Text='<%#String.Format("{0:d}",Eval("PaymentDate"))%>' > </asp:Label>
</ItemTemplate>
</asp:TemplatedField>
</Columns>
</asp:GridView>
So this is the required code for converting into the desired format of data.
thanks.
Masud (15.7.9)
Suppose your column name is
"Amount" should be shown as currency (ex: $100)
"PaymentDate" should be shown as date (ex:7/12/2009), generally SQL 2005 will show it as (7/12/2009 12.00 AM) which is a bad format.
so lets check it out. Suppose we are using TemplatedField in GridView and as field we are using labels ..so the code like this.
<asp:GridView ID="TestGV" runat="server">
<Columns>
<asp:TemplatedField>
<ItemTemplate>
<asp:Label ID="CurrencyLabel" runat="server" Text='<%#String.Format("{0:c}",Eval("Amount"))%>' > </asp:Label>
</ItemTemplate>
</asp:TemplatedField>
<asp:TemplatedField>
<ItemTemplate>
<asp:Label ID="PaymentDateLabel" runat="server" Text='<%#String.Format("{0:d}",Eval("PaymentDate"))%>' > </asp:Label>
</ItemTemplate>
</asp:TemplatedField>
</Columns>
</asp:GridView>
So this is the required code for converting into the desired format of data.
thanks.
Masud (15.7.9)
Monday, July 13, 2009
I could not sleep tonight (14.7.9)
Creation of this blog has an eventual cause. Tonight 14.7.9. I could not sleep for a while. A few days ago (7.6.09) I had Appendix operation and after that operation I found myself very helpless and probably I got mentally sick to some extent. Often I became afraid of becoming great sick and losing something valuable part of my body.
Let me tell u a very dangerous event during my operation.I had local anesthesia during my operation and I was injected in the Spinal chord and I found my better half just dead during my operation. My operation was over but I could not make any sense of my better half for 6+ hours and first 3-4 hours I was lying in post-op room without the presence of my family members. That was tragic matter as I found none and I felt if I lose my better half.That fear still remains in me. I have become mentally weak about my physical condition.
I know some tips...people get scared when something they cant explain. That time one should breathe properly so that fresh oxygen can enters the body and the brain can work properly and empowers one to think logically...but this I cant follow all the time. I should regain this strongly....nothing to fear. Allah is always with us. Tonight I worked for company up to 3.00 am ...then went to sleep but could not sleep and started blogging. I blogged in my professional blog http://masudcseku.blogspot.com. However this blog is going to be my personal blog.
thanks.
Masud(14.7.9)
.
Let me tell u a very dangerous event during my operation.I had local anesthesia during my operation and I was injected in the Spinal chord and I found my better half just dead during my operation. My operation was over but I could not make any sense of my better half for 6+ hours and first 3-4 hours I was lying in post-op room without the presence of my family members. That was tragic matter as I found none and I felt if I lose my better half.That fear still remains in me. I have become mentally weak about my physical condition.
I know some tips...people get scared when something they cant explain. That time one should breathe properly so that fresh oxygen can enters the body and the brain can work properly and empowers one to think logically...but this I cant follow all the time. I should regain this strongly....nothing to fear. Allah is always with us. Tonight I worked for company up to 3.00 am ...then went to sleep but could not sleep and started blogging. I blogged in my professional blog http://masudcseku.blogspot.com. However this blog is going to be my personal blog.
thanks.
Masud(14.7.9)
.
I could not sleep tonight (14.7.9)
Creation of this blog has an eventual cause. Tonight 14.7.9. I could not sleep for a while. A few days ago (7.6.09) I had Appendix operation and after that operation I found myself very helpless and probably I got mentally sick to some extent. Often I became afraid of becoming great sick and losing something valuable part of my body.
Let me tell u a very dangerous event during my operation.I had local anesthesia during my operation and I was injected in the Spinal chord and I found my better half just dead during my operation. My operation was over but I could not make any sense of my better half for 6+ hours and first 3-4 hours I was lying in post-op room without the presence of my family members. That was tragic matter as I found none and I felt if I lose my better half.That fear still remains in me. I have become mentally weak about my physical condition.
I know some tips...people get scared when something they cant explain. That time one should breathe properly so that fresh oxygen can enters the body and the brain can work properly and empowers one to think logically...but this I cant follow all the time. I should regain this strongly....nothing to fear. Allah is always with us. Tonight I worked for company up to 3.00 am ...then went to sleep but could not sleep and started blogging. I blogged in my professional blog http://masudcseku.blogspot.com. However this blog is going to be my personal blog.
thanks.
Masud(14.7.9)
.
Let me tell u a very dangerous event during my operation.I had local anesthesia during my operation and I was injected in the Spinal chord and I found my better half just dead during my operation. My operation was over but I could not make any sense of my better half for 6+ hours and first 3-4 hours I was lying in post-op room without the presence of my family members. That was tragic matter as I found none and I felt if I lose my better half.That fear still remains in me. I have become mentally weak about my physical condition.
I know some tips...people get scared when something they cant explain. That time one should breathe properly so that fresh oxygen can enters the body and the brain can work properly and empowers one to think logically...but this I cant follow all the time. I should regain this strongly....nothing to fear. Allah is always with us. Tonight I worked for company up to 3.00 am ...then went to sleep but could not sleep and started blogging. I blogged in my professional blog http://masudcseku.blogspot.com. However this blog is going to be my personal blog.
thanks.
Masud(14.7.9)
.
Adding client side (javascript) function to ASP.NET server contorl
This is critical things I was looking for many days..that is how to add javascript event to the server side ASP.NET control. This is very needed often but I could not manage it for a long time. However, this time I got some. We have to follow 2 steps.
1. Define client side function
2. Add function/event to the control.
1. Define the client side function
Suppose a text box...I want to limit total chars in it is 100. If we want to use javascript for this then code will be like this. This code will be scripted in the .aspx page...that means will be in the script tag in the main page.
function allowInsert(total) /*here total=100*/
{
var mybox=document.getElementById("mytextbox"); /* server control ID="mytextbox"*/
var text=mybox.value;
var len=text.length;
int mylen=0;
mylen=parseInt(len);
/*testing condition*/
if(mylen< total)return true;
else return false;
}
2. Adding function to the server control
In Page_Load event of .aspx.cs (code-behind) page we have to add the following line
Let mytextbox is the ID of the control.So....
mytextbox.Attributes.Add("onkeyup","javascript:return allowInsert(100)");
Now when a char will be entered in mytextbox then each time this function will be checked
whether it is allowed or not.
thanks.
Masud(14.7.9)
1. Define client side function
2. Add function/event to the control.
1. Define the client side function
Suppose a text box...I want to limit total chars in it is 100. If we want to use javascript for this then code will be like this. This code will be scripted in the .aspx page...that means will be in the script tag in the main page.
function allowInsert(total) /*here total=100*/
{
var mybox=document.getElementById("mytextbox"); /* server control ID="mytextbox"*/
var text=mybox.value;
var len=text.length;
int mylen=0;
mylen=parseInt(len);
/*testing condition*/
if(mylen< total)return true;
else return false;
}
2. Adding function to the server control
In Page_Load event of .aspx.cs (code-behind) page we have to add the following line
Let mytextbox is the ID of the control.So....
mytextbox.Attributes.Add("onkeyup","javascript:return allowInsert(100)");
Now when a char will be entered in mytextbox then each time this function will be checked
whether it is allowed or not.
thanks.
Masud(14.7.9)
Use of stored procedure in a table data show
Most of us heard about the stored procedure. I also heard about it but I could not know how to use it. However stored procedure is very helpful for the big queries which is tough to build every time we use. So centrally a function/procedure is stored and called when we need that certain actions it perform....so this is called stored procedure. Here are some tips about stored procedure.
1.create a stored procedure:
How to build a stored procedure: Suppose u want to show info of the students of CSE discipline.
So the code is:
CREATE procedure dbo.showAllInfo
(
/*parameter list*/
@discipline varchar(50)
)
as
select * from Student where discipline=@discipline
EXEC dbo.showAllInfo
Now save the document using any name and execute this sql in VS or any other tools that has access to DB. When it is executed successfully then you will see a new entry called showAllInfo in the stored procedure folder of your DB.
2. Use of stored procedure
Here is how to use stored procedure. Lets take a glance on it. Let we are using SqlConnection object.
try
{
SqlConnection conn=new SqlConnection(ConfigurationManager.ConnectionStrings["MASUDDBConnectionString"].ConnectionString);
conn.open();
SqlCommand comm=new SqlCommand();
comm.Connection=conn;
comm.CommandText="showAllInfo";
comm.CommandType=CommandType.StoredProcedure;
comm.Parameters.AddWithValue("discipline","ParamValue"); /*paramvalue=CSE*/
SqlDataAdapter sda=new SqlDataAdapter(comm);
DataTable dt=new DataTable();
sda.Fill(dt);
/*databinding*/
SomeGridView.dataSource=dt;
SomeGridView.dataBind();
/*results rendered successfully*/
/*closing conn*/
sda.Dispose();
conn.Close();
}
catch(Exception exc)
{
}
1.create a stored procedure:
How to build a stored procedure: Suppose u want to show info of the students of CSE discipline.
So the code is:
CREATE procedure dbo.showAllInfo
(
/*parameter list*/
@discipline varchar(50)
)
as
select * from Student where discipline=@discipline
EXEC dbo.showAllInfo
Now save the document using any name and execute this sql in VS or any other tools that has access to DB. When it is executed successfully then you will see a new entry called showAllInfo in the stored procedure folder of your DB.
2. Use of stored procedure
Here is how to use stored procedure. Lets take a glance on it. Let we are using SqlConnection object.
try
{
SqlConnection conn=new SqlConnection(ConfigurationManager.ConnectionStrings["MASUDDBConnectionString"].ConnectionString);
conn.open();
SqlCommand comm=new SqlCommand();
comm.Connection=conn;
comm.CommandText="showAllInfo";
comm.CommandType=CommandType.StoredProcedure;
comm.Parameters.AddWithValue("discipline","ParamValue"); /*paramvalue=CSE*/
SqlDataAdapter sda=new SqlDataAdapter(comm);
DataTable dt=new DataTable();
sda.Fill(dt);
/*databinding*/
SomeGridView.dataSource=dt;
SomeGridView.dataBind();
/*results rendered successfully*/
/*closing conn*/
sda.Dispose();
conn.Close();
}
catch(Exception exc)
{
}
Updating an entry of table using mygeneration tool
To change an entry of the table is also interesting and easy. You don't need to write an update query or even think of creating and closing a sql connection...even no chance to hurt a primary key also. Just follow these steps. Lets consider the Admin table. Suppose Admin wants to change the password having AdminID=5. So here lies the following code:
try
{
Admin admin=new Admin();
admin.ConnectionString=ConfigurationManager.ConnectionStrings["MASUDDBConnectionString"].
ConnectionString;
if(admin.LoadByPrimaryKey(5))
{
admin.AdminPassword="new password";
admin.Save();
/*entry updated successfully*/
}
}
catch(Exception exc)
{
/*error notification*/
}
So this is the easiest way to update a table entry as I believe. what do you think about this?
thanks
Masud(14.7.9)
try
{
Admin admin=new Admin();
admin.ConnectionString=ConfigurationManager.ConnectionStrings["MASUDDBConnectionString"].
ConnectionString;
if(admin.LoadByPrimaryKey(5))
{
admin.AdminPassword="new password";
admin.Save();
/*entry updated successfully*/
}
}
catch(Exception exc)
{
/*error notification*/
}
So this is the easiest way to update a table entry as I believe. what do you think about this?
thanks
Masud(14.7.9)
How to show a table data with mygeneration business object?
As from the last blog we came to learn about how to add a new entry in the table without any touch to the table. Lets consider the admin table. So we have got the following things already in hand:
1. _Admin.cs (Abstract class)
2. Admin.cs (Extension of _Admin)
3. Admin.sql (All doodad's stored procedures)
And it is expected we have already added some rows to the table. Now comes how we can show the value from the table. This is the most interesting part of mygeneration tool. You have 2 options
a. show values of one item
b. show values of all items in table
show values of one item:
This is quite easy. Here is the code following.
Suppose AdminID of Admin table is 5. So the following code shows Admin's info having AdminID=5.
try
{
Admin admin=new Admin();
admin.ConnectionString=ConfiguraionManager.ConnectionStrings["MASUDDBConnectionString"].
ConnectionString;
if(admin.LoadByPrimaryKey(5))
{
/*Loaded the single instance*/
Response.write("Email:"+admin.AdminEmail+" Admin Pass:"+admin.AdminPassword+"
");
}
}
catch(Exception exc)
{}
show values for all items:
try
{
--------
same as previous
--------
if(admin.LoadByAll())
{
/*All instances loaded*/
admin.Rewind(); /*setting pointer to 0th row*/
do
{
Response.write("Email:"+admin.AdminEmail+" Admin Pass:"+admin.AdminPassword+"
");
}while(admin.MoveNext());
}
}
catch(Exception exc)
{}
So these are the way to access rows in the table. I think it is quite interesting, isn't it?
thanks.
Masud (14.7.9)
1. _Admin.cs (Abstract class)
2. Admin.cs (Extension of _Admin)
3. Admin.sql (All doodad's stored procedures)
And it is expected we have already added some rows to the table. Now comes how we can show the value from the table. This is the most interesting part of mygeneration tool. You have 2 options
a. show values of one item
b. show values of all items in table
show values of one item:
This is quite easy. Here is the code following.
Suppose AdminID of Admin table is 5. So the following code shows Admin's info having AdminID=5.
try
{
Admin admin=new Admin();
admin.ConnectionString=ConfiguraionManager.ConnectionStrings["MASUDDBConnectionString"].
ConnectionString;
if(admin.LoadByPrimaryKey(5))
{
/*Loaded the single instance*/
Response.write("Email:"+admin.AdminEmail+" Admin Pass:"+admin.AdminPassword+"
");
}
}
catch(Exception exc)
{}
show values for all items:
try
{
--------
same as previous
--------
if(admin.LoadByAll())
{
/*All instances loaded*/
admin.Rewind(); /*setting pointer to 0th row*/
do
{
Response.write("Email:"+admin.AdminEmail+" Admin Pass:"+admin.AdminPassword+"
");
}while(admin.MoveNext());
}
}
catch(Exception exc)
{}
So these are the way to access rows in the table. I think it is quite interesting, isn't it?
thanks.
Masud (14.7.9)
Tuesday, July 7, 2009
Adding a new entry in tha table (using Mygeneration)
If you want to add a new entry in the database table then this topic is going to help you. Let us consider that we have a table in the database called Student and schema like this
table name: Student
Fields:
{
name varchar(50),
roll varchar(10),
cgpa float,
address varchar(50),
email varchar(50),
birthDate smalldatetime
}
During the creation of table two things must be done:
1. setting a column as an identity element with auto-increment 1
2. setting that column as the primary key.
Lets consider how this can be done. Suppose Admin is table
lets create the table using a sql query:
USE BIZNES
go
create table Admin
(
AdminID smallint IDENTITY,
AdminEmail varchar(50),
AdminPassword varchar(50),
Primary key(AdminID)
)
go
SET IDENTITY_INSERT Admin ON
Another Process:
Suppose you have created table using GUI of SQL server 200x and you want add that constraint.Use the following steps:
a. Right click on table and do to table definition
b. Select the desired column and set
Identity=Yes
Autoincrement=1
Not for replication=Yes
c. Set this column as primary key
where BIZNES is the database name. So if you design a table like this using a query
the created table is perfectly suitable for input to mygeneration tool. So please design
your own table setting identity and primary key and generate business objects like _Admin.cs file or other stored procedures.
We have already learned how to create _Student.cs or Student.cs file. If you are not familiar with this please follow my previous blogs about mygeneration tool. So now a small snippet of code is needed for you to add an entry in the database. That is:
Student std=new Student();
std.ConnectionString=ConfigurationManager.ConnectionStrings["MASUDDB
ConnectionString"].ConnectionString;
std.AddNew();
std.name="Masud";
std.roll="040201";
std.cgpa=4.63;
std.address="Farmgate,Dhaka";
std.email="test@gmail.com";
std.birthDate="25/04/1998";
std.Save();
This is how a new row or entry is created in database. You don't need an insert query for getting an entry. You can handle all this in a fine manner...isn't it?
thanks.
Masud
7.7.9
table name: Student
Fields:
{
name varchar(50),
roll varchar(10),
cgpa float,
address varchar(50),
email varchar(50),
birthDate smalldatetime
}
During the creation of table two things must be done:
1. setting a column as an identity element with auto-increment 1
2. setting that column as the primary key.
Lets consider how this can be done. Suppose Admin is table
lets create the table using a sql query:
USE BIZNES
go
create table Admin
(
AdminID smallint IDENTITY,
AdminEmail varchar(50),
AdminPassword varchar(50),
Primary key(AdminID)
)
go
SET IDENTITY_INSERT Admin ON
Another Process:
Suppose you have created table using GUI of SQL server 200x and you want add that constraint.Use the following steps:
a. Right click on table and do to table definition
b. Select the desired column and set
Identity=Yes
Autoincrement=1
Not for replication=Yes
c. Set this column as primary key
where BIZNES is the database name. So if you design a table like this using a query
the created table is perfectly suitable for input to mygeneration tool. So please design
your own table setting identity and primary key and generate business objects like _Admin.cs file or other stored procedures.
We have already learned how to create _Student.cs or Student.cs file. If you are not familiar with this please follow my previous blogs about mygeneration tool. So now a small snippet of code is needed for you to add an entry in the database. That is:
Student std=new Student();
std.ConnectionString=ConfigurationManager.ConnectionStrings["MASUDDB
ConnectionString"].ConnectionString;
std.AddNew();
std.name="Masud";
std.roll="040201";
std.cgpa=4.63;
std.address="Farmgate,Dhaka";
std.email="test@gmail.com";
std.birthDate="25/04/1998";
std.Save();
This is how a new row or entry is created in database. You don't need an insert query for getting an entry. You can handle all this in a fine manner...isn't it?
thanks.
Masud
7.7.9
Thursday, July 2, 2009
Steps for working with Mygeneration tools
After installing the software you will have to follow the following steps to make it completely workable.
1. Create your tables (as per your database design)
2. Create abstract classes
3. Extend the abstract classes
4. Store them in App_Code folder in your website
5. Executing the dooDad's stored procedures
Now lets come step by step
1. Table creation
I think people already know this how to create a table in the a database. Let me remind one important thing those who are working SQL Server 2005 or higher. While connecting to the database then:
Server: (local)\sqlexpress
Here we often write (local)/sqlexpress and generally get an error number 40. Those who are suffering this problem it can be cure for them. Though it is expected people are acquainted with process of table creation however let me give a clear view.
a. Click Server Explorer from View
b. Find Data Connections
c. Data Connection>Create New SQL server database
d.Server: (local)\sqlexpress
e. Now let database name Test..
f. Test>Tables>New Table
g. Generate different fields
h. Save the table
2. Create abstract class
When your expected tables are created then actually your interaction with database is really over. Now mygeneration tool will take care of all the things. So open mygeneration tool and follow the steps.
a.Open>Templates>C#>CSharp_SQL_BusinessObject
b. Execute
c. Now fill the following like these
Output File Path: C:/test folder/
Namespace: TestNamespace
Select a database:Test
Select Table: Maximus
Select Language: C# (default)
d. Press Ok
Now you will find an abstract class named Maximus.cs, but the class file in it named as
_Maximus. It will have following type of code
namespace TestNamespace
{
public class _Maximus
{
/* different codes*/
}
}
So rename the Maximus.cs to _Maximus.cs. And this is the abstract class file for you
which will be used for further database operations
3. Extend abstract class
This is very simple. Lets follow the steps
a. Create a Maximus.cs class file from VS
b. Now open the file and write the following code
public class Maximus: TestNamespace._Maximus
{
}
c. Now save the Maximus.cs file.
4. Store these files
Now an important thing is to store these files where. Follow these steps
a. Create/Open the App_Code folder in your website
b. Create two folder in it named DAL and BO
c. Now store _Maximus.cs in DAL
d. And store Maximus.cs in BO
e. As you storing these files in App_Code so these class files will be automatically complied.
5. Execute the stored procedure
a. Open Mygeneration tool
b. File>New>Mygeneration Project>Add template instance
A window will popup. Now insert the following info
name:test
Template: Microsoft SQL Server>d00Dads Stored Procedures
c. Now click Record Template input
Now another window will popup
d. Insert info like this
Output file path:C:/test/
Select a database: Test
Select table: Maximus
Press Button Ok. and return to previous window and also press Ok
e. You will discover test like
New Project >test
f. Now right click on test and select execure
Here you will find a black screen giving message that stored procedure created successfuly.
g. Now open C:/test. Here you will find a file Maximus.sql
h. Open this file using Mygeneration tool
i. Then execute from toolbar
Now your duty is finished. get relaxed and you can do all database works just calling Maximus class. Now from your website in any page you can create code like this:
Maximus maxOb=new Maximus();
maxOb.Name="Masud";
maxOb.Roll=040201;
where Name and Roll are fields of Maximus table you created. However thats all for today.
Next time I will be more specific using example.
thanks.
Masud(3.7.9)
1. Create your tables (as per your database design)
2. Create abstract classes
3. Extend the abstract classes
4. Store them in App_Code folder in your website
5. Executing the dooDad's stored procedures
Now lets come step by step
1. Table creation
I think people already know this how to create a table in the a database. Let me remind one important thing those who are working SQL Server 2005 or higher. While connecting to the database then:
Server: (local)\sqlexpress
Here we often write (local)/sqlexpress and generally get an error number 40. Those who are suffering this problem it can be cure for them. Though it is expected people are acquainted with process of table creation however let me give a clear view.
a. Click Server Explorer from View
b. Find Data Connections
c. Data Connection>Create New SQL server database
d.Server: (local)\sqlexpress
e. Now let database name Test..
f. Test>Tables>New Table
g. Generate different fields
h. Save the table
2. Create abstract class
When your expected tables are created then actually your interaction with database is really over. Now mygeneration tool will take care of all the things. So open mygeneration tool and follow the steps.
a.Open>Templates>C#>CSharp_SQL_BusinessObject
b. Execute
c. Now fill the following like these
Output File Path: C:/test folder/
Namespace: TestNamespace
Select a database:Test
Select Table: Maximus
Select Language: C# (default)
d. Press Ok
Now you will find an abstract class named Maximus.cs, but the class file in it named as
_Maximus. It will have following type of code
namespace TestNamespace
{
public class _Maximus
{
/* different codes*/
}
}
So rename the Maximus.cs to _Maximus.cs. And this is the abstract class file for you
which will be used for further database operations
3. Extend abstract class
This is very simple. Lets follow the steps
a. Create a Maximus.cs class file from VS
b. Now open the file and write the following code
public class Maximus: TestNamespace._Maximus
{
}
c. Now save the Maximus.cs file.
4. Store these files
Now an important thing is to store these files where. Follow these steps
a. Create/Open the App_Code folder in your website
b. Create two folder in it named DAL and BO
c. Now store _Maximus.cs in DAL
d. And store Maximus.cs in BO
e. As you storing these files in App_Code so these class files will be automatically complied.
5. Execute the stored procedure
a. Open Mygeneration tool
b. File>New>Mygeneration Project>Add template instance
A window will popup. Now insert the following info
name:test
Template: Microsoft SQL Server>d00Dads Stored Procedures
c. Now click Record Template input
Now another window will popup
d. Insert info like this
Output file path:C:/test/
Select a database: Test
Select table: Maximus
Press Button Ok. and return to previous window and also press Ok
e. You will discover test like
New Project >test
f. Now right click on test and select execure
Here you will find a black screen giving message that stored procedure created successfuly.
g. Now open C:/test. Here you will find a file Maximus.sql
h. Open this file using Mygeneration tool
i. Then execute from toolbar
Now your duty is finished. get relaxed and you can do all database works just calling Maximus class. Now from your website in any page you can create code like this:
Maximus maxOb=new Maximus();
maxOb.Name="Masud";
maxOb.Roll=040201;
where Name and Roll are fields of Maximus table you created. However thats all for today.
Next time I will be more specific using example.
thanks.
Masud(3.7.9)
Subscribe to:
Posts (Atom)