ASP.NETR Custom classes that import Excel into SQL databases

Source: Internet
Author: User
Tags empty sql string

ASP.NETR Custom classes that import Excel into SQL databases

The following is a reference fragment:
public class Savetosql
{
public string Strnewcodeid = string. Empty;
public string Strnewcode = string. Empty;
public string strnewdes = string. Empty;
public string Stroldcodeid = string. Empty;
public string Stroldcode = string. Empty;
public string strolddes = string. Empty;
public string Server = string. Empty;
public string DataBase = string. Empty;
public string Uid = string. Empty;
public string Pwd = string. Empty;
private string tablename = String. Empty;
<summary>
The name of the destination table
</summary>
public string Tablenames
{
Get{return TableName;}
Set{tablename=value;}
}
Public Savetosql ()
{
}
<summary>
Save data
</summary>
public void Save ()
{
String Strconpath = String. Format ("server={0};d atabase={1};uid={2};p wd={3}", this. Server,this. Database,this. Uid,this. PWD);
SqlConnection con1 = new SqlConnection (Strconpath);
Con1. Open ();
SqlCommand com1 = new SqlCommand ();
Com1.commandtext = "Insert into" +tablename+ "(newcodeid,newcode,newdes,oldcodeid,oldcode,olddes) Values (' +strNewCodeId+ "', '" +strnewcode+ "," "+strnewdes+" ', ' "+stroldcodeid+", "" +stroldcode+ "," "+strolddes+" ";
COM1. Connection=con1;
COM1. ExecuteNonQuery ();
Con1. Dispose ();
}
}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.