How to load multiple tables in DataSet programmatically ?
DataSet ds= new DataSet();
string strConn="Server=(local);dataBase=Northwind;user id=sa;password=;";
SqlConnection cn = new SqlConnection(strConn);
string strSQL="select * from Customers;select * from employees";
cn.Open();
SqlDataAdapter da = new SqlDataAdapter( strSQL,cn);
ds.Tables.Add("Customers");
ds.Tables.Add("Employees");
ds.EnforceConstraints =false;
ds.Tables["Customers"].BeginLoadData();
da.Fill(ds.Tables["Customers"]);
ds.Tables["Customers"].EndLoadData();
ds.Tables["Employees"].BeginLoadData();
da.Fill(ds.Tables["Employees"]);
ds.Tables["Employees"].EndLoadData();
dataGrid1.DataSource=ds.Tables["Customers"];
dataGrid2.DataSource=ds.Tables["Employees"];
cn.Close();
Wednesday, December 03, 2008
Tuesday, October 21, 2008
Webservice -Basic Authentication
Securing Webservice using IIS - Basic authentication
Once you create a webservice solution using VSS 2008 0r 2009 you MUST host them in IIS server.Please do not use or expect the VSS's built in IIS emulator will take care of authentication for your webservice.
In IIS control panel,choose your webservice directory and set to Basic Authentication checkbox ON.Decheck the Ananoymous authenticate check box.
Supply your computer's user name and password on IIS control for basic authentication.Now you have done 20 percent of secure web service hosting.
Now you need to piece of code in your client application,my code snippet is like
Service s = new Service();
ICredentials cred = new NetworkCredential("murugesa", "pandian", "pp");
s.Credentials = cred;
s.PreAuthenticate = true;
string s1 = s.HelloWorld();
Response.Write(s1);
If you are consuming the webservices from your vendor,please ask them to give their domain name,user name and password which allocated to you.
You can use them on your consume application like above how I used .
Server will check your authentication if fails,it will shows the HTTP 401 status page.
Once you create a webservice solution using VSS 2008 0r 2009 you MUST host them in IIS server.Please do not use or expect the VSS's built in IIS emulator will take care of authentication for your webservice.
In IIS control panel,choose your webservice directory and set to Basic Authentication checkbox ON.Decheck the Ananoymous authenticate check box.
Supply your computer's user name and password on IIS control for basic authentication.Now you have done 20 percent of secure web service hosting.
Now you need to piece of code in your client application,my code snippet is like
Service s = new Service();
ICredentials cred = new NetworkCredential("murugesa", "pandian", "pp");
s.Credentials = cred;
s.PreAuthenticate = true;
string s1 = s.HelloWorld();
Response.Write(s1);
If you are consuming the webservices from your vendor,please ask them to give their domain name,user name and password which allocated to you.
You can use them on your consume application like above how I used .
Server will check your authentication if fails,it will shows the HTTP 401 status page.
Monday, September 22, 2008
XML Attributes and value reading
System.IO.StreamReader stream = new System.IO.StreamReader(@"D:\MyText.xml");
XmlTextReader reader = null;
reader = new XmlTextReader(stream);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an Element.
Response.Write( reader.Name);
while (reader.MoveToNextAttribute()) // Read attributes.
Response.Write(" " + reader.Name + "='" + reader.Value + "'");
break;
case XmlNodeType.Text: //Display the text in each element.
Response.Write(reader.Value);
break;
case XmlNodeType.EndElement: //Display end of element.
Response.Write("" + reader.Name);
Response.Write(">");
break;
}
}
XmlTextReader reader = null;
reader = new XmlTextReader(stream);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an Element.
Response.Write( reader.Name);
while (reader.MoveToNextAttribute()) // Read attributes.
Response.Write(" " + reader.Name + "='" + reader.Value + "'");
break;
case XmlNodeType.Text: //Display the text in each element.
Response.Write(reader.Value);
break;
case XmlNodeType.EndElement: //Display end of element.
Response.Write("" + reader.Name);
Response.Write(">");
break;
}
}
Wednesday, September 17, 2008
Difference between two dates
This codesnippet for finding the differences between two given dates.
You can calculate for the months and years also by using this.
DateTime dt1 = Convert.ToDateTime(TextBox1.Text.ToString());
int t1 = dt1.Day;
DateTime dt2 = Convert.ToDateTime(TextBox2.Text.ToString());
int t2 = dt2.Day;
DateTime r1 = new System.DateTime(dt2.Year, dt2.Month, dt2.Day, 12, 0, 0);
DateTime r2 = new System.DateTime(dt1.Year, dt1.Month, dt1.Day, 12, 0, 0);
System.TimeSpan result = r1 - r2;
Response.Write(result.Days);
You can calculate for the months and years also by using this.
DateTime dt1 = Convert.ToDateTime(TextBox1.Text.ToString());
int t1 = dt1.Day;
DateTime dt2 = Convert.ToDateTime(TextBox2.Text.ToString());
int t2 = dt2.Day;
DateTime r1 = new System.DateTime(dt2.Year, dt2.Month, dt2.Day, 12, 0, 0);
DateTime r2 = new System.DateTime(dt1.Year, dt1.Month, dt1.Day, 12, 0, 0);
System.TimeSpan result = r1 - r2;
Response.Write(result.Days);
Subscribe to:
Posts (Atom)