Monday, March 12, 2012

How to copy single row in datagrid

Hi to all,

I would like to copy data (whole single row at once) from web-based datagrid to off line Excel spreadsheet. I am using Vb.net and Access database.

Please help me!

Regards

Harsh

Here is an example that uses the Northwind database as an example. It creates a CSV file that Excel can open directly, so there is no need to start interfacing with the COM Excel DLL. If your text contains commas, you can use another seperator such as vbTab. Hope this helps

<%@.PageLanguage="VB" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<scriptrunat="server">

ProtectedSub Gridview1_RowCommand(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.GridViewCommandEventArgs)

If e.CommandName ="Export"Then

' Create an instance of StreamWriter to write text to a file.

Using swAs System.IO.StreamWriter =New System.IO.StreamWriter(MapPath("App_Data/TestFile.csv"))

Dim rAs GridViewRow = Gridview1.Rows(CInt(e.CommandArgument))

Dim csvLineAsString =String.Empty

For indexAsInteger = 0To r.Cells.Count - 1

If csvLine =""Then

csvLine = r.Cells(index).Text

Else

csvLine +="," + r.Cells(index).Text

EndIf

Next

sw.WriteLine(csvLine)

sw.Close()

EndUsing

EndIf

EndSub

</script>

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<asp:GridViewID="Gridview1"runat="server"AutoGenerateColumns="False"DataKeyNames="CustomerID"

DataSourceID="SqlDataSource1"OnRowCommand="Gridview1_RowCommand">

<Columns>

<asp:TemplateFieldHeaderText="Click link to Export">

<ItemTemplate>

<asp:LinkButtonID="LinkButton1"runat="server"CommandName="Export"CommandArgument='<%# Container.DataItemIndex %>'>Export</asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

<asp:BoundFieldDataField="CustomerID"HeaderText="CustomerID"ReadOnly="True"SortExpression="CustomerID"/>

<asp:BoundFieldDataField="CompanyName"HeaderText="CompanyName"SortExpression="CompanyName"/>

<asp:BoundFieldDataField="PostalCode"HeaderText="PostalCode"SortExpression="PostalCode"/>

<asp:BoundFieldDataField="Phone"HeaderText="Phone"SortExpression="Phone"/>

</Columns>

</asp:GridView>

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"

SelectCommand="SELECT [CustomerID], [CompanyName], [PostalCode], [Phone] FROM [Customers]">

</asp:SqlDataSource>

</form>

</body>

</html>


Thanks sbyard for the code. I appreciate you. I will try this code and hope it will help me.

Regards

Harsh

Labels: , , , , , , , , , ,

How to copy new data from server to a local database.

Can somebody tell me what is the easiest way to copy new data from MySQL database placed on server to a local Access 2003 DB on my computer? (Using Visual Basic 2005 PRO)

I want to copy whole rows (about 25 columns: strings, doubles, booleans and one BLOB).

Thanks

you need two connections that return two datatables once you have your datatables you can do something like this If the table schemas are the same :

MyAccessDT.Merge(MySQLDT)

Labels: , , , , , , , , , , ,

How to copy an Access database using ADO.NET and C#??

Hi all,
I have an Access '97 database called "dbHLS", inside this database I have a
table called "tbHLS". I would like to copy the table tbHLS from within the
dbHLS.mdb to an Access 2002 database called "dbTarget". Obviously as I'm
copying the table tbHLS I dont want anything to do with the table to change
other than the location of it.
Can this be done? if so how can it be done' Anyone know of any links?
Thanks in advance.
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-ado-net/200511/1On Fri, 18 Nov 2005 16:54:31 GMT, "Jon S via DotNetMonster.com" <u2272@.uwe> wrote:
¤ Hi all,
¤
¤ I have an Access '97 database called "dbHLS", inside this database I have a
¤ table called "tbHLS". I would like to copy the table tbHLS from within the
¤ dbHLS.mdb to an Access 2002 database called "dbTarget". Obviously as I'm
¤ copying the table tbHLS I dont want anything to do with the table to change
¤ other than the location of it.
¤
¤ Can this be done? if so how can it be done' Anyone know of any links?
The following code will create the table and copy the data. However, it will not create any indexes
or primary keys, etc.
Function ExportAccessToAccess() As Boolean
Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"
& _
"Data Source=e:\My Documents\dbHLS.mdb")
AccessConn.Open()
Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT * INTO [MS
Access;DATABASE=E:\My Documents\dbTarget.mdb;].[tbHLS] FROM tbHLS", AccessConn)
AccessCommand.ExecuteNonQuery()
AccessConn.Close()
Paul
~~~~
Microsoft MVP (Visual Basic)

Labels: , , , , , , , , ,

how to Copy a table from mssql to ms access

Is there any way to copy a table(structure and data) from mssql to ms access?
Moved from the C# language group to the .NET Data access and storage group, as that's much more relevant here.
Jon

Labels: , , , , , ,

How to convert database MS Access to oracle?

How to convert database MS Access to oracle?

My database in MS access 2003. and i want to convert that database in to ORACLE 8i. please guide me for the same. thanks in advance.

You will have to do it manually.

First, create your tables in Oracle.
Next, Export your Access data to a CSV file.
Then use the Oracle command line took, Sql Loader to inport your data from the CSV file into your new Oracle tables.

No you don't.

There are tools by Oracle as well as all kinds of other vendors to do this automatically.

Start here:

http://www.oracle.com/technology/tech/migration/focusareas/access.html


ASPDavid wrote:

No you don't.

There are tools by Oracle as well as all kinds of other vendors to do this automatically.

Start here:

http://www.oracle.com/technology/tech/migration/focusareas/access.html


Thanks for the liink. I wasn't aware Oracle had a tool for importing Access files.

However, I don't ever recommend third-party tools since they involve $$$.
SQL Loader had worked fine for me for years.
dweezil.....can you be more specific...pls....
I have the same problem and I can't find a surce code aniware........can you help me with some....[-o<

BRUX wrote:

dweezil.....can you be more specific...pls....
I have the same problem and I can't find a surce code aniware........can you help me with some....[-o<


Export your Access database to a csv file or whatever file extension you want to use.
Create a corresponding table in Oracle.
Create a control for SQL*Loader:
Load Data
INFILE 'c:\mydatafile.csv
INTO table my_oracle_table_name
fields terminated by "," optionally enclosed by '"'
(
column_1,
column_2
)


Save the above control file as: access.ctl

Open a command prompt and type:
set oracle_sid = myoracle_sid
sqlldr username/password control= access.ctl log=mydatafile.log

Check the log file for any records that failed.

Also, look at Oracle's free developer tool,SQL Developer. I believe it has SQL*Loader funcitionality in it.

Good luck!

Labels: , , , , , , ,