For Answers, see/post comments

Create xml file

This sample code shows how to generate XML and write to a file.

Imports System.Xml
Imports System.IO
Imports System.Data.SqlClient

Public Function CreateXML() As Boolean
Dim objDataSet As DataSet
Dim intI As Integer
Dim strPath As String
Dim objWriter As XmlTextWriter
'create an instance of the XmlTextWriter object

Try
' location to the XML file to write
strPath = strFilePath & "\XML\" & strSessionID & ".xml"
objWriter = New XmlTextWriter(strPath, System.Text.Encoding.Default)
' start writing the XML document
objWriter.WriteStartDocument()
' write a comment in our XML file
objWriter.WriteComment("Employee")
' starting with the root element i.e. "movies"
objWriter.WriteStartElement("Menu")
'Create dataset as per your requirement.Here xml for Employee is created.The elements are Empno,Emp_name and salary
'Set data to XML tags


If objDataSet.Tables(0).Rows.Count > 0 Then
For intI = 0 To objDataSet.Tables(0).Rows.Count - 1
objWriter.WriteStartElement("Employee") ' output the "Employee" element
objWriter.WriteElementString("EmpNo", objDataSet.Tables(0).Rows(intI).Item("EmpNo").ToString)
objWriter.WriteElementString("Name", objDataSet.Tables(0).Rows(intI).Item("Emp_Name").ToString)
objWriter.WriteElementString("Salary", objDataSet.Tables(0).Rows(intI).Item("Salary"))
objWriter.WriteEndElement() ' close "Employee" element
Next
End If
' end the "Menu" element
objWriter.WriteEndElement()
' flush and write XML data to the file
objWriter.Flush()
Return True

Catch ex As Exception
Return False
Finally
' clear up memory
objWriter.Close()
objWriter = Nothing
objDataSet = Nothing
End Try
End Function

How to write ScriptManager and Javascripts for Ajax

When using Ajax Update panels on a page , simple javascript functions do not work as these scripts are not in the "ScriptManagers pool", to execute javascripts like for eg an alert do the following:
ScriptManager.RegisterStartupScript(this,typeof(Page), "alertFn", "alert('test');", true);

Creating and invoking custom events

Events are used to handle the situations dynamically. Let say almost in all the windows application we are using button control, and the click event of it. Actually the click is happening in the button control, but user [we] able to handle the click event in form. The same way we can use the events for our own controls, business objects etc.Example:Class “Store” is used to add and delete the items. Also the class has the event called “OnDelete”, which is used to handle something before the delete operation. The user of the “Store” class can write his codes required to execute before the delete operation.In this example I have handled the OnDelete event to show the warning message while deleting.

// Declare a delegate for the event handler.
public delegate void StoreEventHandler(string itemName,ref bool action);
public class Store
{
// Declare an event handler
public event StoreEventHandler OnDelete;
private Dictionary ItemList = new Dictionary();

public void Add(int Id,string Name)
{
ItemList.Add(Id,Name);
}

public void Delete(int Id)
{
bool canDelete=false;
//fire the on delete event[s]
OnDelete(ItemList[Id], ref canDelete);
if (canDelete)
{
ItemList.Remove(Id);
MessageBox.Show("Item Deleted sucessfully");
}
else
{
MessageBox.Show("Deletion canceld by the user");
}
}
}


How to use the Store object in your application:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
Store myStore = new Store();
myStore.OnDelete += new StoreEventHandler(myStore_OnDelete
myStore.Add(1, "Milk");
myStore.Add(2, "Biscuts");
myStore.Delete(2);
}

void myStore_OnDelete(string itemName, ref bool action)
{
DialogResult r = MessageBox.Show("Are you sure you want to delete item '"+itemName+"' from the store","Confirm Item Delete", MessageBoxButtons.YesNo);

if (r == DialogResult.Yes)
{
action = true;
}
else
{
action = false;
}
}
}

function in vb.net

Hi friends,

I've written a funciton to strip all special characters. But the space is not working.. help me. my coding is

Public Function strip(ByVal des As String)

Dim strorigFileName As String

Dim intCounter As Integer

Dim arrSpecialChar() As String = {".", ",", "<", ">", ":", "?", """", "/", "{", "[", "}", "]", "`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "-", "+", "=", "", " ", "\"}

strorigFileName = desintCounter = 0Do Until intCounter = 29

des = Replace(strorigFileName, arrSpecialChar(intCounter), "")

intCounter = intCounter + 1

strorigFileName = des

Loop

Return strorigFileName

End Function

asp.net vs asp Options

This is a basic overall question. Please note I am new to ASP!
I am currently running IIS 5/Access 2000/Windows 2000 and have developed a web application.
From what I have been told, to really emulate a master/detail form, the best way would be to use ASP.net to do so.
1. is that true?
2. if so, does ASP.net run against Access or SQLServer?
3. what would I need to purchase to emulate this?

Thank you for your help.

Multitier application and Datagrid Options

Hello,

I'm trying to understand how can I write a application in three layers and use a datagrid on a object.

For example, let's say I have a table on my database (COUNTRIES) with the fields ID and DESCRIPTION. And I have a class Country that would connect to this table:
class Country {

public int ID {
get;
set;
}
public string Description { get; set; }
}


Now, I know I can create a data source out of this object and connect it to a datagrid.

But how then can I handle things updates, inserts and deletions in the datagrid?

Thank you in advance,

Delete text file file

using System;

using System.IO;

class Test {

public static void Main()
{

string path = @"c:\temp\MyTest.txt";
using (StreamWriter sw = File.CreateText(path)) {}

string path2 = path + "temp";

// Ensure that the target does not exist.
File.Delete(path2);
// Copy the file.
File.Copy(path, path2);
// Delete the newly created file.
File.Delete(path2);
}
}

Allow only one row to get updated in disconnected data access

To alter the default behavior of the DataAdapter object which does multiple-row changes to thedatabase, the following code updates only the first row modified to the database irrespective of any rows you changed.

sqlDataAdapter1.UpdateBatchSize = 1;

DataSet1 ds = (DataSet1)dataSet11.GetChanges();

sqlDataAdapter1.Update(ds);dataSet11.AcceptChanges();

MessageBox.Show("Only the first of the modified rows updated!");

sqlDataAdapter1.Fill(dataSet11);

how to use a SqlDataAdapter to get data from a database into a DataSet

Dim sConnection As String = "server=local);uid=sa;pwd=password;database=yourDatabase"
Dim objDataAdapter As New SqlDataAdapter("Select * From tableName", sConnection)
Dim dsResult As New DataSet("Result")If Not IsNothing(objDataAdapter) Then
' Fill data into dataset
objDataAdapter.Fill(dsResult)
objDataAdapter.Dispose()
End If
' Test by bind data into datagridview control
Me.DataGridView1.DataSource = dsResult.Tables(0)

Session state might be invalid or corrupted Error Options

Hi,
I have a Web Farm scenario in my application where i am storing the
custom User Object in Session and all the session state

information is stored in Oracle Database .My Session Handler class
inherits from SessionStateStoreProviderBase class.


Structure of User Object is follows


User Contains Object of Generic List of Type Role Object


Role Object contains Generic List of Type Permission Object


Here is complete stack trace of exception


System.Web.HttpException: The session state information is invalid and
might be corrupted. at
System.Web.SessionState.SessionStateItemCollection.Deserialize(BinaryReader
reader) at SessionStateProviderManager.deserialize(HttpContext
p_context, String p_serializedItems, Int32 p_timeout)


Does any one has idea on this error 'Session state information is
invalid and might be corrupted' ?.


that under which scenario do we get this error and what are possible
remedies

Session state might be invalid or corrupted Error Options

Hi,
I have a Web Farm scenario in my application where i am storing the
custom User Object in Session and all the session state

information is stored in Oracle Database .My Session Handler class
inherits from SessionStateStoreProviderBase class.


Structure of User Object is follows


User Contains Object of Generic List of Type Role Object


Role Object contains Generic List of Type Permission Object


Here is complete stack trace of exception


System.Web.HttpException: The session state information is invalid and
might be corrupted. at
System.Web.SessionState.SessionStateItemCollection.Deserialize(BinaryReader
reader) at SessionStateProviderManager.deserialize(HttpContext
p_context, String p_serializedItems, Int32 p_timeout)


Does any one has idea on this error 'Session state information is
invalid and might be corrupted' ?.


that under which scenario do we get this error and what are possible
remedies

Problem Reading Excel XML Options

Hi,

I've saved an Excel spreadsheet to XML using Excel 2003 and now want
to read it using VB.net
Below, I've pasted an abbreviated snippet from the XML file. The
actual file is really long, but this section should demonstrate my
problem. I am trying to read this file using VB.net and find the
Worksheet node using the following code:


Dim xmlDocument As new XmlDocument
xmlDocument.Load(sFileName)
Dim aNode As XmlNode = xmlDocument.SelectSingleNode("//Workbook")


I've tried several different XPath syntaxes and I've also tried
looking for different nodes. I can't seem to get anything, even though
the code works when I test it with a simpler XML file not generated by
Excel.


Can anyone help me retrieve and navigate XML nodes in this Excel
generated XML file please?


Thanks for any help.




xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">

x:FullColumns="1"
x:FullRows="1">





ss:Type="String">EIR - Monthly Queries



ss:Type="String">Criteria Chosen: Reported Date between 2008/03/01 AND
2008/03/31