Dubli Join Us

Search About New Technology and Bug

Loading...

Wednesday, December 21, 2011

Ms Excel in C#,VB.Net Could not find installable ISAM

When you are going to use Ms Excel in c#, If you get this error when importing a excel file 

use this connection string 

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +Server.MapPath("Master.xlsx") + ";Extended Properties='Excel 12.0;HDR=YES;'" 


"HDR=Yes;" indicates that the first row contains columnnames, not data. "HDR=No;" indicates the opposite. 

Print Div ,HTML or Table Content in Asp.net Using C#

Following is the code for printing  Div ,HTML or Table to printer using C# in Asp.net


<script type="text/javascript" language="javascript">
    function print()
    {
    var printFriendly = document.getElementById("div1")
    var printWin = window.open("about:blank","Voucher","menubar=no;status=no;toolbar=no;");
    printWin.document.write("<html><head><title>Voucher Report</title></head><body><h1>Agent Wise Report</h1>" + printFriendly.innerHTML + "</body></html>");
    printWin.document.close();
    printWin.window.print();   
    printWin.close();
    }
   
    </script>

add this script lines in your header section of given page.

<div id="div1">
<table width="100%">
    <tr>
    <td align="center" width="225px" >
    <img  height="30px" src='<%#Eval("logoimage")%>'width="100px" /><br />
    </td>
    </tr>
    </table>
</div>

this is div that is going to print.Mainly the id of div tag is "div1".

<asp:Button ID="btnPrint" runat="server" Text="Print" OnClick="btnPrint_Click" />


on button click event put the following code to handle print task.

btnPrint.Attributes.Add("onClick", "print();");


That's final.


In DataGridView Get the index of the SelectedRow

following is the code how to do that 

private void DataGridView1_SelectionChanged(object sender, EventArgs e) 


if (dataGridView1.SelectedRows.Count == 1) 

txtName.Text = dataGridView1.Rows[DataGridView1.SelectedRows[0].Index].Cells["Name"].Value.ToString(); 


}