Upload Data from Local System Ms Access to Web Sql Server? -
i have windows forms application maintains billing details of company's employees. application stores , manipulates data in ms access database. have send data every sql server web database employees can see monthly reports on website. code :
private sub uploaddata() dim conn new oledb.oledbconnection("connection string ms access db") dim scon = new sqlconnection(" web sql sever connection") try scon.open() catch ex exception msgbox(ex.message) exit sub end try dim qcmd new sqlcommand("select query", scon) dim cmd new oledbcommand("select id,acc,newacc,city,name,billduedateamt,oldbalance records city = 'delhi'", conn) dim mrdr oledbdatareader = cmd.executereader try while mrdr.read qcmd.commandtext = "insert billing (acc,newacc,city,name,billduedateamt,oldbalance) values (" + _ mrdr.item(0) + "," + mrdr.item(1) + ... on ")" qcmd.executenonquery() end while catch ex exception msgbox(ex.message) if scon.state <> connectionstate.closed scon.close() end if conn.close() end try end sub
it's slow, there better code so?
here short of code showing bulkcopy.
private static void performbulkcopydifferentschema() { string connectionstring = @"server= localhost;database=northwind;trusted_connection=true"; datatable sourcedata = new datatable(); // source data using (sqlconnection sourceconnection = new sqlconnection(connectionstring)) { sqlcommand mycommand = new sqlcommand("select top 5 * products_archive", sourceconnection); sourceconnection.open(); sqldatareader reader = mycommand.executereader(); // open destination data using (sqlconnection destinationconnection = new sqlconnection(connectionstring)) { // open connection destinationconnection.open(); using (sqlbulkcopy bulkcopy = new sqlbulkcopy(destinationconnection.connectionstring)) { bulkcopy.columnmappings.add("productid", "productid"); bulkcopy.columnmappings.add("productname", "name"); bulkcopy.columnmappings.add("quantityperunit", "quantity"); bulkcopy.destinationtablename = "products_topselling"; bulkcopy.writetoserver(reader); } } reader.close(); } }
Comments
Post a Comment