Dot Net Learning Zone Blog

A blog about to learn Dot Net

Archive for December, 2010

Entity Framework – SaveChanges() doesn’t get the generated Identity key

Posted by Rajesh on December 24, 2010

Step to get identity key
Suppose T_Emp is table placed on emp.edmx. Now open with emp.edmx in xml and find EntityType Name=”T_EMP”.
Finally , what you have to do add StoreGeneratedPattern=”Identity” in primary key . Now Save the edmx and execute the project.
Now you can get identity key after SaveChanges()

Entities e1 = new Entities();
T_Empl a = new T_Empl();
a.Name = “Rajesh”;
e1.AddToT_Empl(a);
e1.SaveChanges();
var id = a.ID;
——————————————————
<EntityType Name=”T_EMP”>
<Key>
<PropertyRef Name=”ID” />
</Key>
<Property Name=”ID” Type=”number” Nullable=”false” StoreGeneratedPattern=”Identity”/>
<Property Name=”Name” Type=”varchar2″ MaxLength=”100″ />
</EntityType>

Posted in Entity framework | Leave a Comment »

How to validate text box with only numeric value with two decimal place

Posted by Rajesh on December 24, 2010

We have created a sample project in windows form in c#. There is a text box which accept only numeric value with decimal like 1234.56.
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

string strNumber = “0123456789.”;

private void textBox1_Leave(object sender, EventArgs e)
{

textBox1.Text = Convert.ToDecimal ( textBox1.Text).ToString(“N2″).Replace (“,”,”");
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (strNumber.IndexOf(e.KeyChar) == -1)
{
e.Handled = true;
}

if ((textBox1.Text.IndexOf(‘.’) > -1) && (e.KeyChar == ‘.’))
{
e.Handled = true ;
}

}
}
}

Posted in Windows Form | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.