DataSet ds = new NewsRule().GetNews(); string outString = string.Empty; string fileName = string.Empty; StreamWriter sw = null; foreach (DataTable dt in ds.Tables) { string colName = string.Empty; foreach (DataColumn dc in dt.Columns) { colName += string.Format("{0},", dc.ColumnName); } foreach (DataRow dr in dt.Rows) { string colValue = string.Empty; foreach (DataColumn dc in dt.Columns) { if (dc.DataType.ToString() == "System.Int32" || dc.DataType.ToString() == "System.Double" || dc.DataType.ToString() == "System.Decimal") { colValue += string.Format("{0},", dr[dc].ToString()); } else { colValue += string.Format("'{0}',", dr[dc].ToString()); } } outString += string.Format("Insert into {0}({1}) values({2})/n", dt.TableName, colName.Substring(0, colName.Length - 1), colValue.Substring(0, colValue.Length - 1)); } fileName = string.Format("{0}//{1}.sql", "E:", dt.TableName); sw = new StreamWriter(fileName, false, Encoding.Default); sw.Write(outString); sw.Flush(); sw.Close(); }