Dot Net Capsules

A Capsule on .NET, everyday, keeps you .NetHealthy!!!!

My Photo
Name:

Co-founder at mymoneysage.in Result oriented Tech Leader Programmer, Sotware Architect, Techologist Polyglot software developer, expert in multiple tech stack Specialties: Machine learning, Artificial intelligence, Conversational Interface, RASA, AWS, Lex, REST, GraphQL, PWA, C#, .NET, ASP.NET, XML, Web services, Agile, SCRUM

Tuesday, April 26, 2005

Using Trasaction with DataAdapters

Following are the steps to use SqlTransaction with SqlDataAdapter
1. Create a Connection :
SqlConnection con = new SqlConnection(connectionString);
Con.Open();


2. Create a Transaction :
SqlTransaction tran = con.BeginTrasaction();

3. Create a Command object :
SqlCommand command = new SqlCommand(query);

4. Create a DataAdapter :
SqlDataAdapter dataAdapter = new SqlDataAdapter(con);
dataAdapter.SelectCommand = command;
//Fill a dataset
//modify dataset
//Create Update, Insert, Delete command using SqlCommandBuilder and SqlDataAdapter
//update the data into Dataset to Database using update method
dataAdapter.Update(dataset);

5. Commit or Rollback the Trasaction :
Tran.Commit();
Or
Tran.Rollback();

When you create a DataAdapter using the Connection object, Trasaction associated with the connection object is also associated with the DataAdapter object.

Converting an Integer to Binary format

Use Convert.ToString(number, 2) to convert an integer to Binary format.
Following is the sample code:

public string IntToBinary(int num) {
return Convert.ToString(num, 2) ;
}


when you call this function passing number 3 it will return '11' and when you call this function passing number 300 it will return '100101100'.

So how's that!!!!!!!!!!!

Creating Controls Dynamically using Reflection

I have published this code months back at Developerdex. Republishing here.
The following method can be used in WinForms to create a control dynamically and put it on a
Windows forms.

Just the pass a fully quolified name of the control, for example "System.Windows.Forms.TextBox" and the function will do the rest, ie it will create the control, set the basic properties and place the control in a panel, here pnlDynControl.

For this method to work I have assumed that the assembly in which the control is defined is loaded into the memory and it is referenced by "myAssem" global variable(not necessary, u can change it). and the Control is derived from "System.Windows.Forms.Control" Class.

So here is the function:

private void CreateControl(string controlType)

{

System.Windows.Forms.Control ctrlDyn ;

Type t = myAssem.GetType(controlType) ;

System.Reflection.ConstructorInfo[] ctorInfo = t.GetConstructors() ;

pnlDynControl.Controls.Clear() ;

if(ctorInfo.Length >=0)

{

ctrlDyn = (System.Windows.Forms.Control)ctorInfo[0].Invoke(null) ;

ctrlDyn.Location = new Point(20,80) ;

ctrlDyn.Visible = true ;

ctrlDyn.Text = "Hi all" ;

ctrlDyn.Width = 100 ;

ctrlDyn.Height = 50 ;

pnlDynControl.Controls.Add(ctrlDyn) ;

}

}

Monday, April 18, 2005

ASP.NET QuickStart Tutorial

Hi All, Today's small capsule. Just check out the ASP.NET 2.0 QuickStart Tutorial. A good place to start next version of ASP.NET 2.0

Friday, April 8, 2005

First Capsule

This is the first capsule of this blog!!! Will try to post something everyday as a capsule on .NET and related technology.

You Visitor Number:
Free Web Site Counter
Free Counter
free counters