ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories >> Code-Snippets >> Programming-Code >> Dot-Net-Code
 
  ASP.NET-Code (40)  VB.NET-Code (2)  C-Sharp-Code (22)  ADO.NET-Code (5)
 


 

Back to Questions Page
 
Question
How to get the row index on checking a Checkbox in a ListView
Rank Answer Posted By  
 Question Submitted By :: San
I also faced this Question!!   © ALL Interview .com
Answer
1.
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5e6653e7-8503-44b8-ab0d-e0de7ace07f5

2.
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/52e1fdd6-3841-4f47-955c-79c85b37ad43/

3.
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/1c25c338-2b50-4c30-aac6-b3676700dff6

4.
http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.languages.csharp/2007-10/msg02293.html

5. 
http://www.codeverge.net/ng.asp-net-forum.vs_2005_web_application_projects/how-to-get-row-id-with-html-checkbox-in-gridview

6.
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/d8d8508c-5295-44bc-be76-0c9d25ebae8b

7. 
http://stackoverflow.com/questions/1060864/c-listview-unable-to-check-a-checkbox-strange-problem

8. 
http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=7196
 
0
San
 
 
Question
how to convert Dataset to Object Array or list in c# .net
Rank Answer Posted By  
 Question Submitted By :: Kris
I also faced this Question!!   © ALL Interview .com
Answer
1-->
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/5b1c29e2-bf37-4dd2-be39-50d27abb188e

2-->
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/8d3834a8-2749-4bd6-a32b-f8a162a5b641

3-->
http://programming.top54u.com/post/ASP-Net-C-sharp-Convert-DataSet-to-ArrayList.aspx

4-->
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/24b786da-fc87-4264-b934-5a0381ca6bdc
 
0
Sona
 
 
Answer
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/24b786da-fc87-4264-b934-5a0381ca6bdc

this one works fine.

            DataTable dt = ds.Tables[0];
            List<Employee> emp = new List<Employee>();
            foreach (DataRow dr in dt.Rows)
            {
                Employee em = new Employee();
                em.Name = dr["Name"].ToString();
                em.age = Convert.ToInt32(dr["Age"]);
                em.Salary = Convert.ToInt32(dr["Salary"]);
                emp.Add(em);
            }
 
0
San
 
 
 
Answer
DataTable dt = ds.Tables[0];
            List<Employee> emp = new List<Employee>();
            foreach (DataRow dr in dt.Rows)
            {
                Employee em = new Employee();
                em.Name = dr["Name"].ToString();
                em.age = Convert.ToInt32(dr["Age"]);
                em.Salary = Convert.ToInt32(dr["Salary"]);
                emp.Add(em);
            }
 
0
Mohan
 
 
Question
how to design a ListView control?
Rank Answer Posted By  
 Question Submitted By :: Sona
I also faced this Question!!   © ALL Interview .com
Answer
</tr> <asp:ListView ID="lstBank" runat="server" 
OnItemCommand="lstBank_ItemCommand" >
                                    <LayoutTemplate>
                                        <table border="0" 
cellpadding="4" class="tblGrid tblAccount">
                                            <tr>
                                               <th 
style="text-align:center; width: 90px">
                                                    
<asp:Label ID="lblVoucherNo" Text="Voucher No" 
runat="server"></asp:Label>
                                                </th>
                                                <th 
style="text-align:left; width: 90px">
                                                    
<asp:Label ID="lblDate" Text="Date" 
runat="server"></asp:Label>
                                                </th>
                                                
                                                <th 
style="text-align:left; width: 90px">
                                                    
<asp:Label ID="lblChequeNo" Text="Cheque No" 
runat="server"></asp:Label>
                                                </th>
                                                <th 
style="text-align:left; width: 90px">
                                                    
<asp:Label ID="lblChequeDate" Text="Cheque Date" 
runat="server"></asp:Label>
                                                </th>
                                              
                                                <th 
style="text-align:left; width: 90px">
                                                    
<asp:Label ID="lblAmount" Text="Amount" 
runat="server"></asp:Label>
                                                </th>
                                                <th 
style="text-align:left; width: 90px">
                                                    
<asp:Label ID="lblPartyName" Text="Party Name" 
runat="server"></asp:Label>
                                                </th>
                                                
                                                <th 
style="text-align:left; width: 90px">
                                                    
<asp:Label ID="lblDate" Text="Date" 
runat="server"></asp:Label>                                 
                   
                                                </th>
                                                <th 
style="text-align:center; width: 50px">
                                                    
<asp:Label ID="lblCheck" Text="Check" 
runat="server"></asp:Label>
                                                </th>
                                                
                                            </tr>
                                            
<asp:PlaceHolder runat="server" 
ID="itemPlaceholder"></asp:PlaceHolder>
                                            <tr 
class="gridOddRow gridOddRowListUser">
                                                <td 
colspan="10" class="noBrdrBtm noBrdrRght">
                                                    <table 
class="tblTotalRecords">
                                                        <tr 
class="removeHoverColor">
                                                            
<td valign="top" align="left">
                                                            
    <div style="text-align: left; padding-top: 4px; 
vertical-align: text-bottom">
                                                            
        Total Records:
                                                            
        <asp:Label ID="lblTotalRecords" runat="server" 
Text="1"></asp:Label>
                                                            
    </div>
                                                            
</td>
                                                            
<td valign="middle">
                                                            
    <div style="text-align: center;">
                                                            
        Page Size:
                                                            
        <asp:DropDownList AutoPostBack="true" 
OnSelectedIndexChanged="ddlPagingSize_OnSelectedIndexChanged
"
                                                            
            CssClass="PagingDropDownStyle" 
ID="ddlPagingSize" name="ddlPagingSize" runat="server">
                                                            
        </asp:DropDownList>
                                                            
    </div>
                                                            
</td>
                                                            
<td align="center" valign="middle" colspan="10">
                                                            
    <div style="text-align: center;">
                                                            
        <asp:LinkButton ID="lnkPrev" CommandName="Prev" 
ToolTip="Previous" runat="server"> << </asp:LinkButton>
                                                            
        Page
                                                            
        <asp:TextBox OnKeyPress="return DoPagingOnEnter();" 
runat="server" Width="18px" Height="12px"
                                                            
            Style="text-align: center; font-family: Arial; 
font-size: 11px;" Text="1" ID="txtPage"></asp:TextBox>
                                                            
        of
                                                            
        <asp:Label ID="lblCount" 
runat="server">1</asp:Label>
                                                            
        page(s)
                                                            
        <asp:LinkButton ID="lnkNext" CommandName="Next" 
ToolTip="Next" runat="server"> >> </asp:LinkButton>
                                                            
    </div>
                                                            
</td>
                                                     
                                                    </table>
                                                </td>
                                            </tr>
                                        </table>
                                    </LayoutTemplate>
                                    <ItemTemplate>
                                        <tr id="idRows" 
onclick="return ChangeRowColor(this);" class="<%# 
Container.DisplayIndex % 2 == 
0 ? "gridOddRow" : "gridEvenRow" %>" >
                                             <td 
style="display:none" >
                                                <asp:Label 
runat="server" Text='<%# Eval("VoucherId")%>' 
ID="lblVoucherId"></asp:Label>
                                            </td>
                                            <td>
                                                <asp:Label 
runat="server" Text='<%# Eval("VoucherNumber")%>' 
ID="lblVoucherNo"></asp:Label>
                                            </td>
                                            <td>
                                                <asp:Label 
runat="server" Text='<%# Eval
("VoucherDate","{0:dd/MM/yyyy}")%>'  
                                                    
ID="lblDate"></asp:Label> 
                                            </td>
                                            <td>
                                                <asp:Label 
runat="server" Text='<%# Eval("ChequeDDNo")%>' ToolTip='<%# 
Eval("ChequeDDNo")%>'
                                                    
ID="lblChequeNo"></asp:Label>
                                            </td>
                                            <td >
                                                <asp:Label 
runat="server" Text='<%# Eval
("ChequeDDDate","{0:dd/MM/yyyy}")%>' 
ID="lblChequeDate"></asp:Label>
                                            </td>
                                            <td>
                                                <asp:Label 
runat="server" Text='<%# Eval("Amount")%>' 
ID="lblAmount"></asp:Label>
                                            </td>
                                            <td >
                                                <asp:Label 
runat="server" Text='<%# Eval("PartyName")%>' 
ID="lblPartyName"></asp:Label>
                                            </td>
                                            
                                            <td 
>                                            
                                              <asp:TextBox 
runat="server" ID="txtDate" Text='<%# Eval
("ReconciledDate","{0:dd/MM/yyyy}")%>'  class="txtNormal 
CustomWidth" onkeypress="Date_Only();" > </asp:TextBox>
                                           
<ajax:CalendarExtender ID="calDate" 
PopupPosition="BottomRight" Format="dd/MM/yyyy"
                                                    
TargetControlID="txtDate" runat="server">
                                                
</ajax:CalendarExtender>
                                            </td>
                                            <td >
                                               
<asp:CheckBox runat="server" ID="chkRec"  value='< %# Eval
("VoucherNumber")%>'  OnCheckedChanged="chkRec_checked" 
AutoPostBack="true" /> <%--onMouseDown=<%#"return TestCheck
('"+ Eval("Amount") +"',this);"%>--%>
                                            </td>
                                            
                                        </tr>
                                    </ItemTemplate>
                                    <EmptyDataTemplate>
                                        <table border="0" 
cellpadding="4" class="tblGrid tblAccount">
                                            <tr>
                                            <th 
style="display: 
none">                                                     
                                                        
<asp:Label ID="lblVoucherId" Text="Voucher Id" 
runat="server"></asp:Label>                                 
                                                            
     
                                                </th>
                                                <th 
style="padding-left: 4px; width: 
100px">                                                   
                                                    Voucher 
No                                                   
                                                
                                                <th 
style="padding-left: 4px; width: 
150px">                                                     
                                                        
<asp:Label ID="lblCurrency" Text="Voucher Date" 
runat="server"></asp:Label>                                 
                                                            
     
                                                </th>
                                                <th 
style="text-align:right; width: 100px">
                                                    
<asp:Label ID="lblChequeNo" Text="Cheque No" 
runat="server"></asp:Label>
                                                </th>
                                                <th 
style="text-align:right; width: 110px">
                                                    
<asp:Label ID="lblChequeDate" Text="Cheque Date" 
runat="server"></asp:Label>
                                                </th>
                                                </th>
                                                <th 
style="padding-left: 4px; width: 
180px">                                                    
                                                        
<asp:Label ID="lblAmount" Text="Amount" 
runat="server"></asp:Label>                                 
                   
                                                </th>
                                                <th 
style="padding-left: 4px; width: 
180px">                                                    
                                                        
<asp:Label ID="lblPartyName" Text="Party" 
runat="server"></asp:Label>                                 
                   
                                                </th>
                                                
                                                <th 
style="padding-left: 4px; width: 
180px">                                                    
                                                        
<asp:Label ID="lblDate" Text="Reconcile Date" 
runat="server"></asp:Label>                                 
                   
                                                </th>
                                                <th 
style="padding-left: 4px; width: 
180px">                                                    
                                                        
<asp:Label ID="lblCheck" Text="Reconcile" 
runat="server"></asp:Label>                                 
                   
                                                </th>
                                                
                                            </tr>
                                            <tr>
                                                <td 
class="gridOddRow" colspan="10">
                                                    <center>
                                                        
<b>No records found.</b>
                                                    
</center>
                                                </td>
                                            </tr>
                                        </table>
                                    </EmptyDataTemplate>
                                </asp:ListView>
 
0
Kris
 
 
Question
hold checkbox values
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
private void CheckChkBoxStatusHold()
        {           
            ArrayList objChkBoxID = new ArrayList();   
            if (Cache[(Session["Userid"] 
+ "BankReconChkBoxID")] != null)
            {
                objChkBoxID=(ArrayList)Cache[(Session
["Userid"] + "BankReconChkBoxID")];
            }           
              for (int i = 0; i < CurPageCnt; i++)
            {
                if (intCheckSave == 1)
                {
                    if (((CheckBox)
lstBankReconcilation.Items[i].FindControl
("chkReconcile")).Checked == true)
                    {
                        objChkBoxID.Add(((Label)
lstBankReconcilation.Items[i].FindControl
("lblVoucherId")).Text);
                        DateTime dtReconDate = 
Convert.ToDateTime((((TextBox)lstBankReconcilation.Items
[i].FindControl("txtReconcileDate")).Text), new CultureInfo
("hi-IN"));
                        objChkBoxID.Add(dtReconDate.ToString
("dd-MMM-yyyy"));

                    }
                }
                else if (intCheckSave == 0)
                {
                    if (((CheckBox)
lstBankReconcilation.Items[i].FindControl
("chkReconcile")).Checked == false)
                    {
                        objChkBoxID.Add(((Label)
lstBankReconcilation.Items[i].FindControl
("lblVoucherId")).Text);
                        DateTime dtReconDate = 
Convert.ToDateTime((((TextBox)lstBankReconcilation.Items
[i].FindControl("txtReconcileDate")).Text), new CultureInfo
("hi-IN"));
                        objChkBoxID.Add(dtReconDate.ToString
("dd-MMM-yyyy"));
                       }
                }
            }          
            Cache.Remove((Session["Userid"] 
+ "BankReconChkBoxID"));
            Cache[(Session["Userid"] 
+ "BankReconChkBoxID")] = objChkBoxID;
        }
 
0
Sona
 
 
Answer
this one fr retrieving

private void CheckChkBoxStatusRetrieve()
        { 
            ArrayList objChkBoxRetrieve=new ArrayList();
            if (Cache[(Session["Userid"] 
+ "BankReconChkBoxID")] != null)
            { 
                objChkBoxRetrieve=(ArrayList)Cache[(Session
["Userid"] + "BankReconChkBoxID")];
                for (int j = 0; j < 
objChkBoxRetrieve.Count; j++)
                {
                    for (int i = 0; i < CurPageCnt; i++)
                    {
                        if (objChkBoxRetrieve[j].ToString() 
== ((Label)lstBankReconcilation.Items[i].FindControl
("lblVoucherId")).Text)//lblVoucherNo
                        {
                            ((CheckBox)
lstBankReconcilation.Items[i].FindControl
("chkReconcile")).Checked = true;
                            ((TextBox)
lstBankReconcilation.Items[i].FindControl
("txtReconcileDate")).Text =  DateTime.Now.ToString
("dd/MM/yyyy");
                        }
                    }
                }
            }
        }
 
0
Sona
 
 
Answer
private List<int> IDs
    {
        get
        {
            if (this.ViewState["IDs"] == null)
            {
                this.ViewState["IDs"] = new List<int>();
            }
            return (List<int>)this.ViewState["IDs"];
        }
    }


    protected void AddRowstoIDList()
    {
        int checkAction = 0;

        foreach (ListViewDataItem lvi in lvUsersinGroup.Items)
        {
            CheckBox chkSelect =
(CheckBox)lvi.FindControl("chkSelect");
            if ((((chkSelect) != null)))
            {
                int ID =
Convert.ToInt32(lvUsersinGroup.DataKeys[lvi.DisplayIndex].Value);


                if ((chkSelect.Checked &&
!this.IDs.Contains(ID)))
                {
                    this.IDs.Add(ID);
                    checkAction += 1;
                }
                else if ((!chkSelect.Checked &&
this.IDs.Contains(ID)))
                {
                    this.IDs.Remove(ID);
                }
            }
        }


    }
 
0
Kris
 
 
Answer
1] 
http://blog.evonet.com.au/post/2008/08/Maintaining-Checkbox-State-in-a-Listview.aspx

2] 
http://demo.evonet.com.au/MaintainingListviewCheckboxState.aspx

3] 
http://www.codeproject.com/KB/webforms/States_of_CheckBoxes.aspx

4]  http://forums.asp.net/t/1282544.aspx

5] 
http://www.ilearnttoday.com/index.php/c-aspnet-gridview-how-to-keep-modified-data-of-template-fields-when-paging-is-enabled/comment-page-1
 
0
Sona
 
 
Question
Can you declare an array of mixed Types?
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
public struct FormStruct
{

public string Name ;
public string Address;
public int Phone;

}
class Program
{

static void Main(string[] args)
{

FormStruct home;
home.Name = "xyz";
home.Address= "blabla";
home.Phone= 9955511122;

}

}
 
0
Kris
 
 
Question
working with arrays
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
Initializing Arrays

C# provides simple and straightforward ways to initialize
arrays at declaration time by enclosing the initial values
in curly braces ({}). The following examples show different
ways to initialize different kinds of arrays.

    Note   If you do not initialize an array at the time of
declaration, the array members are automatically initialized
to the default initial value for the array type. Also, if
you declare the array as a field of a type, it will be set
to the default value null when you instantiate the type.

Single-Dimensional Array

int[] numbers = new int[5] {1, 2, 3, 4, 5};
string[] names = new string[3] {"Matt", "Joanne", "Robert"};

You can omit the size of the array, like this:

int[] numbers = new int[] {1, 2, 3, 4, 5};
string[] names = new string[] {"Matt", "Joanne", "Robert"};

You can also omit the new operator if an initializer is
provided, like this:

int[] numbers = {1, 2, 3, 4, 5};
string[] names = {"Matt", "Joanne", "Robert"};

Multidimensional Array

int[,] numbers = new int[3, 2] { {1, 2}, {3, 4}, {5, 6} };
string[,] siblings = new string[2, 2] { {"Mike","Amy"},
{"Mary","Albert"} };

You can omit the size of the array, like this:

int[,] numbers = new int[,] { {1, 2}, {3, 4}, {5, 6} };
string[,] siblings = new string[,] { {"Mike","Amy"},
{"Mary","Albert"} };

You can also omit the new operator if an initializer is
provided, like this:

int[,] numbers = { {1, 2}, {3, 4}, {5, 6} };
string[,] siblings = { {"Mike", "Amy"}, {"Mary", "Albert"} };

Jagged Array (Array-of-Arrays)

You can initialize jagged arrays like this example:

int[][] numbers = new int[2][] { new int[] {2,3,4}, new
int[] {5,6,7,8,9} };

You can also omit the size of the first array, like this:

int[][] numbers = new int[][] { new int[] {2,3,4}, new int[]
{5,6,7,8,9} };

-or-

int[][] numbers = { new int[] {2,3,4}, new int[] {5,6,7,8,9} };

Notice that there is no initialization syntax for the
elements of a jagged array.
Accessing Array Members

Accessing array members is straightforward and similar to
how you access array members in C/C++. For example, the
following code creates an array called numbers and then
assigns a 5 to the fifth element of the array:

int[] numbers = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
numbers[4] = 5;

The following code declares a multidimensional array and
assigns 5 to the member located at [1, 1]:

int[,] numbers = { {1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10} };
numbers[1, 1] = 5;

The following is a declaration of a single-dimension jagged
array that contains two elements. The first element is an
array of two integers, and the second is an array of three
integers:

int[][] numbers = new int[][] { new int[] {1, 2}, new int[]
{3, 4, 5}
};

The following statements assign 58 to the first element of
the first array and 667 to the second element of the second
array:

numbers[0][0] = 58;
numbers[1][1] = 667;
 
0
Kris
 
 
Question
working with fileUpload ?
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
<asp:FileUpload ID="FileUpload1" runat="server"
onchange="change(this);" />


//js
function change(fileupload) {

            if (fileupload.value.indexOf('jpg') == '-1') {
                document.getElementById('TextBox1').value =
'Nopicture';
                alert('Select *.jpg file only');
            }
            if (fileupload.value.indexOf('jpg') != '-1') {
                document.getElementById('TextBox1').value =
'haspicture';
             }

         }

         function changevalue() {
             if
(document.getElementById('FileUpload1').value == '') {
                 alert('Please select a file');
                 return false;
             }
              if
(document.getElementById('FileUpload1').value !='')
               {
                  if
(document.getElementById('FileUpload1').value.indexOf('jpg')
== '-1') {

                      alert('upload *.jpg images only');
                      return false;
                  }
              }

 
//code behind
protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (btnUpload.Text == "Upload")
        {
            if (FileUpload1.HasFile)
            {

                Stream imgStream =
FileUpload1.PostedFile.InputStream;

                int imgLen =
FileUpload1.PostedFile.ContentLength;
                byte[] img = new byte[imgLen];
                int n = imgStream.Read(img, 0, imgLen);
                Session["Picture"] = img;
                lblMessage.Text = "Attached";
                btnUpload.Text = "Remove";
            }
            else
            {
                Session["Picture"] = null;
            }

        }
        else
        {
            Session["Picture"] = null;
            btnUpload.Text = "Upload";
            lblMessage.Text = "Removed";
        }
    }
 
0
Guest
 
 
Question
how to upload an excel in c# ASP.Net?
Rank Answer Posted By  
 Question Submitted By :: Kris
I also faced this Question!!   © ALL Interview .com
Answer
protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (fuUpload.HasFile)
        {
            string filename = fuUpload.PostedFile.FileName;
           
            string strConn;
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
+"Data Source="+ filename +";" +"Extended Properties=Excel
8.0;";
            OleDbConnection con = new OleDbConnection(strConn);
            con.Open();
            OleDbCommand cmd = new OleDbCommand("select *
from [Sheet1$]",con);
            OleDbDataAdapter dad = new OleDbDataAdapter();
            dad.SelectCommand = cmd;
            DataSet ds= new DataSet();
            dad.Fill(ds);
            DataGrid1.DataSource = ds.Tables[0].DefaultView;
            DataGrid1.DataBind();
            con.Close();
        }

    }
 
0
Kris
 
 
Answer
var uploadPath = Server.MapPath("xx/fdd") + @"\" + 
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                .
                if (flupload.PostedFile.FileName.Length > 0)
                {
                    if (flupload.PostedFile.ContentType !
= "application/octet-stream") //  text/plain
                    {
                        ShowMessage("' Error'");
                        return;
                    }
                    if (GetFileType
(flupload.PostedFile.FileName) != ".xls")
                    {
                           ShowMessage("'Error'");
                        return;
                    } 
                    //Upload the selected diary file for 
furhter processing.
                    varFileName = Path.GetFileName
(flupload.PostedFile.FileName);
                    varFileName = uploadPath + @"\" + 
varFileName;
                    flupload.SaveAs(varFileName);






  //Get File type - only csv file is considered here..
        private string GetFileType(string fileName)
        {
            return fileName.Substring(fileName.LastIndexOf
("."), fileName.Length - fileName.LastIndexOf("."));
        }





 public DataTable ReadExcelIntoDataTable(string filename, 
string SheetName)
        {
            string connectionString 
= "Provider=Microsoft.Jet.OLEDB.4.0;" +
                                      "Data Source=" + 
filename + ";" +
                                      "Extended 
Properties=Excel 8.0;";

            OleDbConnection objConn = new OleDbConnection
(connectionString);
            objConn.Open();
            OleDbCommand ObjCommand = new OleDbCommand
("SELECT * FROM [" + SheetName + "$]", objConn);
            OleDbDataAdapter objAdp = new OleDbDataAdapter
();
            objAdp.SelectCommand = ObjCommand;
            DataSet excelSheetDataSet = new DataSet();
            objAdp.Fill(excelSheetDataSet);
            DataTable excelSheetTable = 
excelSheetDataSet.Tables[0];
            objConn.Close();
            return excelSheetTable;

        }



 private string ReadImportedDataFromFile(string uploadPath)
        {
            string[] StrSheetNames = GetExcelSheetNames
(uploadPath);
            DataTable excelSheetTable = 
ReadExcelIntoDataTable(uploadPath, StrSheetNames[5]);
            StringBuilder sbExcel= new StringBuilder();
            int rowCount = 0, colCount = 0;             
            sbExcel.AppendFormat("<{0}>", "home");  
            foreach (DataRow dr in excelSheetTable.Rows)
            {
                if (rowCount >= 1)
                {
                    sbExcel.AppendFormat("<{0}>", "Table");
                    foreach (DataColumn dc in 
excelSheetTable.Columns)
                    {
                                             
                        if (dr[dc].ToString().Trim
().Length != 0)
                        {
                            if (colCount > 1)
                            {
                                sbExcel.AppendFormat
("<EmpCode>{0}</EmpCode>", dr[0].ToString().Trim());  
                                sbExcel.AppendFormat
("<SalHeadId>{0}</SalHeadId>", dc.ColumnName.Trim());
                                //sbExcel.AppendFormat("<" 
+ dc.ColumnName.Trim() + ">{0}</" + dc.ColumnName.Trim() 
+ ">", dr[dc].ToString());
                                sbExcel.AppendFormat("<Rate>
{0}</Rate>", dr[dc].ToString());                         
                            }
                            //else
                            //{
                            //    //string strFormat = 
(colCount == 0 ? "<EmpCode>{0}</EmpCode>" : "<EmpName>{0}
</EmpName>");
                            //    //sbExcel.AppendFormat
(strFormat,dr[dc].ToString().Trim());
                            //}
                            colCount++;
                        }                    
                    }
                    sbExcel.AppendFormat("</{0}>", "Table");
                    colCount = 0;
                }
                rowCount++;
            }           
            sbExcel.AppendFormat("</{0}>", "home");



        }
 
0
Sona
 
 
Question
Data Reader Vs DataSet
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   TCS
I also faced this Question!!   © ALL Interview .com
Answer
data reader reads data and store it in table.
while dataset contains one or more datatable within itself.
datasets are connection less while datareader required
connection to read data.
 
0
Gajendra
 
 
Question
on running a vb.net form to add data to an sql server 
database am getting an error -> the item "obj\debug\windows 
application1.form1.resources"was specified more than oncein 
the "resources" parameter .duplicateitems are not supported 
by the the "resources" parameter. anyone with the solution 
to the problem
Rank Answer Posted By  
 Question Submitted By :: Steve
I also faced this Question!!   © ALL Interview .com
Answer
you may have to create primary key on your database field and you are entering this field duplicate
thats y this error occur
like you have already enter 101 in id field and you trying to enter 101 again 
thats y it would happen
 
0
Kohinoor
 
 
Question
what is the value that reside in a hidden field when no 
value is assigned to it?how it can be used in a if 
statement??
Rank Answer Posted By  
 Question Submitted By :: Prakash Kuttappan
I also faced this Question!!   © ALL Interview .com
Answer
If No value assigned to a hidden field then it contains 
String.Empty value.

Habling empty value:

<%@ Page Language="VB" AutoEventWireup="true" 
CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 
1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Demo</title>
</head>
<body>
    <form id="form1" runat="server">          
<asp:HiddenField ID="hndField" runat="server" />
           </form>
</body>
</html>

Code behind...
  Protected Sub Page_Load(ByVal sender As Object, ByVal e 
As System.EventArgs) Handles Me.Load

        If hndField.Value <> String.Empty Then
do......
        End If
    End Sub
 
0
Rupinder
 
 
 
Back to Questions Page
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com