如题,偶自己的代码:private void button1_Click(object sender, EventArgs e)
{
BindingSource DataBinding = new BindingSource(this.SampleDataTable,null);
this.dataGridView1.DataSource = DataBinding;
}
private int GetExcelCon()
{
string connection = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = C:\\Documents and Settings\\yangjh\\桌面\\sample.xls;Extended Properties=Excel 8.0";
OleDbConnection thisconnection = new OleDbConnection(connection);
string command = "select * from [sheet1$]";
thisconnection.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(command, thisconnection);
DataSet ds = new DataSet();
adapter.Fill(ds, "[sheet1$]");
thisconnection.Close();
foreach (DataRow Row in ds.Tables[0].Rows)
{
/*疑难所在:我只是想将这个DataTable的0列数据依次传递到存储过程"t_StoreAndSale"中的参数
@FFullNumber中,根据返回的行,构造成一个N行的DataTable,然后BindingSource到
DataGridView中,下面这段语句不知道该如何写了,请高手指点,或代码演示*/
//int RowCount=ds.Tables[0].Rows.Count;
}
//?return ds.Tables[0].Columns[0];
}
private DataTable SampleDataTable
{
get
{
string connection = "Server=192.100.3.3;Datasource=AIS20090330165131;uid=sa;pwd=;";
SqlConnection thisconntion = new SqlConnection(connection);
SqlCommand cmd = thisconntion.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "t_StoreAndSale";
cmd.CommandTimeout = 0;
SqlParameter parameter = new SqlParameter("@FFullNumber", SqlDbType.VarChar, 40);
parameter.Direction = ParameterDirection.ReturnValue;
parameter.Value = GetExcelCon();
cmd.Parameters.Add(parameter);
SqlDataAdapter Adapter = new SqlDataAdapter();
Adapter.SelectCommand = cmd;
DataSet ds = new DataSet();
Adapter.Fill(ds);
return ds.Tables[0];
}
}
{
BindingSource DataBinding = new BindingSource(this.SampleDataTable,null);
this.dataGridView1.DataSource = DataBinding;
}
private int GetExcelCon()
{
string connection = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = C:\\Documents and Settings\\yangjh\\桌面\\sample.xls;Extended Properties=Excel 8.0";
OleDbConnection thisconnection = new OleDbConnection(connection);
string command = "select * from [sheet1$]";
thisconnection.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(command, thisconnection);
DataSet ds = new DataSet();
adapter.Fill(ds, "[sheet1$]");
thisconnection.Close();
foreach (DataRow Row in ds.Tables[0].Rows)
{
/*疑难所在:我只是想将这个DataTable的0列数据依次传递到存储过程"t_StoreAndSale"中的参数
@FFullNumber中,根据返回的行,构造成一个N行的DataTable,然后BindingSource到
DataGridView中,下面这段语句不知道该如何写了,请高手指点,或代码演示*/
//int RowCount=ds.Tables[0].Rows.Count;
}
//?return ds.Tables[0].Columns[0];
}
private DataTable SampleDataTable
{
get
{
string connection = "Server=192.100.3.3;Datasource=AIS20090330165131;uid=sa;pwd=;";
SqlConnection thisconntion = new SqlConnection(connection);
SqlCommand cmd = thisconntion.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "t_StoreAndSale";
cmd.CommandTimeout = 0;
SqlParameter parameter = new SqlParameter("@FFullNumber", SqlDbType.VarChar, 40);
parameter.Direction = ParameterDirection.ReturnValue;
parameter.Value = GetExcelCon();
cmd.Parameters.Add(parameter);
SqlDataAdapter Adapter = new SqlDataAdapter();
Adapter.SelectCommand = cmd;
DataSet ds = new DataSet();
Adapter.Fill(ds);
return ds.Tables[0];
}
}
解决方案 »
- socket客户端的一个端口同时发送多个文件应该做不到吧
- 初学C#,请都如何用for对窗体内的label1---label10进行环境遍历?
- c# 怎么判断word文档中那个文本被加粗了!!
- 到底该怎么写Insert语句来插入空值:System.DBNull类型的值不能转化为System.Nullable(of Integer)???
- C# 求个DataGridView操作的完整DEMO?
- 如何判断一个对象是struct
- 有什么更好的办法把DataRow[]组成DataTable呢?
- 直线的生成算法
- Enterprise Library: Configuration Application Block的问题。。。
- [急]高分求教关于c#的简单问题 期待高手指教~~~~~在线等~~~~~~
- <?xml namespace="" prefix="asp" ?> vs2005创建控件
- C#如何动态生成ppt幻灯片 并且自动播放呢
//读Excel到DataGridView
private void RedExcel()
{
string sPath = "F:\\excel名称.xls";
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sPath + ";Extended Properties='Excel 8.0;HDR=NO;IMEX=1'"; string strSQL = "SELECT * FROM [sheet1$]";
OleDbConnection excelConnection = new OleDbConnection(connectionString);
excelConnection.Open(); OleDbCommand dbCommand = new OleDbCommand(strSQL, excelConnection);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(dbCommand); DataTable dTable = new DataTable(); dataAdapter.Fill(dTable); dataGridView1.DataSource = dTable; dTable.Dispose();
dataAdapter.Dispose();
dbCommand.Dispose();
excelConnection.Close();
excelConnection.Dispose();
}
上面代码就可以读取了
/// 数据从Excel到DataSet
/// </summary>
/// <param name="ds">DataSet</param>
public clsExcelReport(DataSet ds)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "导入 Microsoft Excel Document";
dlg.Filter = "Microsoft Excel|*.xls";
if (dlg.ShowDialog() == DialogResult.OK)
{
try
{
fileName = dlg.FileName;
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + dlg.FileName + ";" + "Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";";
using (OleDbConnection conn = new OleDbConnection(strConn))
{
conn.Open();
System.Data.DataTable tables = conn.GetSchema("Tables");
string ss = "select * from [" + tables.Rows[0]["Table_Name"].ToString() + "]";
using (OleDbDataAdapter myCommand = new OleDbDataAdapter(ss, conn))
{
myCommand.Fill(ds);
}
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
CDataCenter.runInfo = ex.ToString();//TODO:李明20091021
}
}
}
string strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;";
strConnection += @"Data Source=C:\Documents and Settings\v-changl\My Documents\couse.xlsx;";
strConnection += "Extended Properties=\"Excel 12.0 Xml;HDR=YES\";";
OleDbConnection objConnection = new OleDbConnection(strConnection);
objConnection.Open();
OleDbDataAdapter myCommandd = new OleDbDataAdapter("select * from [Sheet1$]", objConnection);
DataSet ds = new DataSet();
myCommandd.Fill(ds, "[Sheet1$]");
System.Data.DataTable dt = ds.Tables["[Sheet1$]"];
Console.WriteLine(dt.Columns[0].ToString());
Console.WriteLine(dt.Columns[1].ToString());
DataRow drDisplay = dt.Rows[0];
int[] num = new int[dt.Columns.Count];
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/LCL_data/archive/2009/05/06/4154784.aspx
存储过程好像不能用datatable来作参数吧
{
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = new SqlCommand("库存明细_布料_按订单", clsSql.cn);
adp.SelectCommand.CommandType = CommandType.StoredProcedure; SqlParameter 日期 = adp.SelectCommand.Parameters.Add("@日期", SqlDbType.VarChar, 50);
日期.Direction = ParameterDirection.Input; SqlParameter 订单编号 = adp.SelectCommand.Parameters.Add("@订单编号", SqlDbType.VarChar, 50);
订单编号.Direction = ParameterDirection.Input; SqlParameter 物料编号 = adp.SelectCommand.Parameters.Add("@物料编号", SqlDbType.VarChar, 50);
物料编号.Direction = ParameterDirection.Input; SqlParameter 颜色 = adp.SelectCommand.Parameters.Add("@颜色", SqlDbType.VarChar, 50);
颜色.Direction = ParameterDirection.Input; SqlParameter 色号 = adp.SelectCommand.Parameters.Add("@色号", SqlDbType.VarChar, 50);
色号.Direction = ParameterDirection.Input; SqlParameter 规格 = adp.SelectCommand.Parameters.Add("@规格", SqlDbType.VarChar, 50);
规格.Direction = ParameterDirection.Input; SqlParameter 成份 = adp.SelectCommand.Parameters.Add("@成份", SqlDbType.VarChar, 50);
成份.Direction = ParameterDirection.Input; SqlParameter 克重 = adp.SelectCommand.Parameters.Add("@克重", SqlDbType.VarChar, 50);
克重.Direction = ParameterDirection.Input; SqlParameter 布封 = adp.SelectCommand.Parameters.Add("@布封", SqlDbType.VarChar, 50);
布封.Direction = ParameterDirection.Input; 日期.Value = date;
订单编号.Value = dd;
物料编号.Value = no;
颜色.Value = color;
色号.Value = sehao;
规格.Value = guige;
成份.Value = chengfen;
克重.Value = kezhong;
布封.Value = bufeng; DataSet ds = new DataSet(); adp.Fill(ds); return ds;
}
你参考
parameter.Value = GetExcelCon();Value是一个object对象
那你也可以先写一个如同我贴的那样的方法,然后循环你读EXCEL得到的dataset,将要传递的参数传到存储过程循环执行啊
{
//这里我直接拷贝你的代码了
string connection = "Server=192.100.3.3;Datasource=AIS20090330165131;uid=sa;pwd=;";
SqlConnection thisconntion = new SqlConnection(connection);
SqlCommand cmd = thisconntion.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "t_StoreAndSale";
cmd.CommandTimeout = 0; //...将你要传进存储过程的参数安装我9楼的办法传进去 cmd.Parameters.Add(parameter);
SqlDataAdapter Adapter = new SqlDataAdapter();
Adapter.SelectCommand = cmd;
DataSet ds = new DataSet();
Adapter.Fill(ds);
return ds.Tables[0];
}
循环//读excel得到dataset后
for(int i=0;i<dataset.Table[0].Rows.Count;i++)
{
//ExecPrc();这里调用那个存储过程方法,将要传进去的参数传进去
//处理你得到的datatable也在这里
}
List<string> parms = new List<string>();
DataSet dt = new DataSet();
foreach (DataRow item in dt.Tables[0].Rows)
{
parms.Add(item[0].ToString());
}
{
string strconn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + "; Extended Properties=excel 8.0;";//HDR=Yes;IMEX=1
OleDbConnection conn = null;
try
{
conn = new OleDbConnection(strconn);
conn.Open();
DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
List<String> names = new List<string>();
foreach (DataRow dr in schemaTable.Rows)
{
names.Add(dr["TABLE_NAME"].ToString().Replace("''","'"));
}
return names.ToArray();
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (conn != null)
conn.Close();
} }
/// <summary>
/// 从一个Excel中读取一个Table
/// Table必须是标准的
/// </summary>
/// <param name="file"></param>
/// <param name="sheetName"></param>
/// <returns></returns>
public DataTable TableRead(string fileName, string tableName)
{
// TODO: Add ImpExcel.ReadExcel implementation
string strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + "; Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";//修改读取数丢失的BUG
OleDbConnection conn = null;
try
{
conn = new OleDbConnection(strconn);
conn.Open();
if (tableName.IndexOf("$")==-1)
{
tableName = tableName + "$";
}
string sql = "select * from [" + tableName + "]";
OleDbDataAdapter aper = new OleDbDataAdapter(sql, conn);
DataSet myset = new DataSet();
aper.Fill(myset, tableName);
return myset.Tables[0];
}
catch (Exception ex)
{
if (ex.Message.Contains("is not a valid name"))
throw new DBException(Resources.FileReadWriteResource.MSGIsnotfind + tableName, ex);
else
throw new DBException(Resources.FileReadWriteResource.MSGReadexcelexception, ex);
}
finally
{
if (conn != null)
conn.Close();
}
} public string FilterIParameterBadWord(string str)
{
return str.Replace("(", "_").Replace(")", "_");
} public DbType GetDbType(Type _type)
{
try
{
DbType dtype = (DbType)Enum.Parse(typeof(DbType), _type.Name);
return dtype;
}
catch
{
return DbType.String;
}
}
/// <summary>
/// 把一个DataTable写入到一个Excel Sheet中。
/// Sheet中必须包含对应的Column.
/// </summary>
/// <param name="file"></param>
/// <param name="desTable"></param>
/// <param name="sheetName"></param>
public void WriteExcel(string file, DataTable desTable, string sheetName)
{
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + file + "; Extended Properties=excel 8.0";
OleDbConnection objConn = null;
try
{
objConn = new OleDbConnection(connString);
objConn.Open();
OleDbCommand objCmd = new OleDbCommand();
objCmd.Connection = objConn; objCmd.Parameters.Clear();
string sqlString = "INSERT INTO [" + sheetName + "$]({0}) values ({1})"; string fieldString = "";
string valueString = "";
for (int i = 0; i < desTable.Columns.Count; i++)
{
if (fieldString != "")
{
fieldString += ",";
valueString += ",";
}
fieldString += "[" + desTable.Columns[i].ColumnName + "]";
valueString += "@" + FilterIParameterBadWord(desTable.Columns[i].ColumnName) + "";
OleDbParameter op = new OleDbParameter();
op.ParameterName = "@" + FilterIParameterBadWord(desTable.Columns[i].ColumnName) + "";
op.DbType = GetDbType(desTable.Columns[i].DataType);
objCmd.Parameters.Add(op);
} sqlString = string.Format(sqlString, fieldString, valueString);
objCmd.CommandText = sqlString; //遍历DataSet将数据插入新建的Excel文件中
foreach (DataRow row in desTable.Rows)
{
for (int i = 0; i < desTable.Columns.Count; i++)
{
objCmd.Parameters["@" + FilterIParameterBadWord(desTable.Columns[i].ColumnName) + ""].Value = row[desTable.Columns[i].ColumnName];
}
objCmd.ExecuteNonQuery();
}
objCmd.Connection.Close();
}
catch (Exception ex)
{
throw new DBException(Resources.FileReadWriteResource.MSGWritetoexcelexception, ex);
}
finally
{
if (objConn != null)
objConn.Close();
}
}
一个很好用的Excel操作类~
//读excel得到dataset后
for(int i=0;i<dataset.Table[0].Rows.Count;i++)
{
ExecPrc(dataset.Table[0].Rows[i].Cells[0].ToString());
//这里调用那个存储过程方法,将要传进去的参数传进去
//处理你得到的datatable也在这里
}
晕了,我上面代码不是提示你了么,你在取得excel的datatable后,你再循环那个datatable然后将你需要的某一列的值传进去!
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Reflection;
using Excel;namespace ImportExportToExcel
{
public class ImportExportToExcel
{
private string strConn ;
private System.Windows.Forms.OpenFileDialog openFileDlg=new System.Windows.Forms.OpenFileDialog();
private System.Windows.Forms.SaveFileDialog saveFileDlg=new System.Windows.Forms.SaveFileDialog();
public ImportExportToExcel()
{
//
// TODO: 在此处添加构造函数逻辑
//
this.openFileDlg.DefaultExt = "xls";
this.openFileDlg.Filter = "Excel文件 (*.xls)|*.xls"; this.saveFileDlg.DefaultExt="xls";
this.saveFileDlg.Filter= "Excel文件 (*.xls)|*.xls"; }
#region 从Excel文件导入到DataSet
// /// <summary>
// /// 从Excel导入文件
// /// </summary>
// /// <param name="strExcelFileName">Excel文件名</param>
// /// <returns>返回DataSet</returns>
// public DataSet ImportFromExcel(string strExcelFileName)
// {
// return doImport(strExcelFileName);
// }
/**//// <summary>
/// 从选择的Excel文件导入
/// </summary>
/// <returns>DataSet</returns>
public DataSet ImportFromExcel()
{
DataSet ds=new DataSet();
if (openFileDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
ds=doImport(openFileDlg.FileName);
return ds;
}
/**//// <summary>
/// 从指定的Excel文件导入
/// </summary>
/// <param name="strFileName">Excel文件名</param>
/// <returns></returns>
public DataSet ImportFromExcel(string strFileName)
{
DataSet ds=new DataSet();
ds=doImport(strFileName);
return ds;
}
/**//// <summary>
/// 执行导入
/// </summary>
/// <param name="strFileName">文件名</param>
/// <returns>DataSet</returns>
private DataSet doImport(string strFileName)
{
if (strFileName=="") return null;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + strFileName + ";" +
"Extended Properties=Excel 8.0;";
OleDbDataAdapter ExcelDA = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn); DataSet ExcelDs = new DataSet();
try
{
ExcelDA.Fill(ExcelDs, "ExcelInfo");
}
catch(Exception err)
{
System.Console.WriteLine( err.ToString() );
}
return ExcelDs;
}
#endregion #region 从DataSet到出到Excel
/**//// <summary>
/// 导出指定的Excel文件
/// </summary>
/// <param name="ds">要导出的DataSet</param>
/// <param name="strExcelFileName">要导出的Excel文件名</param>
public void ExportToExcel(DataSet ds,string strExcelFileName)
{
if (ds.Tables.Count==0 || strExcelFileName=="") return;
doExport(ds,strExcelFileName);
}
/**//// <summary>
/// 导出用户选择的Excel文件
/// </summary>
/// <param name="ds">DataSet</param>
public void ExportToExcel(DataSet ds)
{
if (saveFileDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
doExport(ds,saveFileDlg.FileName);
}
/**//// <summary>
/// 执行导出
/// </summary>
/// <param name="ds">要导出的DataSet</param>
/// <param name="strExcelFileName">要导出的文件名</param>
private void doExport(DataSet ds,string strExcelFileName)
{
Excel.Application excel= new Excel.Application();
// Excel.Workbook obj=new Excel.WorkbookClass();
// obj.SaveAs("c:\zn.xls",Excel.XlFileFormat.xlExcel9795,null,null,false,false,Excel.XlSaveAsAccessMode.xlNoChange,null,null,null,null); int rowIndex=1;
int colIndex=0; excel.Application.Workbooks.Add(true);
System.Data.DataTable table=ds.Tables[0] ;
foreach(DataColumn col in table.Columns)
{
colIndex++;
excel.Cells[1,colIndex]=col.ColumnName;
} foreach(DataRow row in table.Rows)
{
rowIndex++;
colIndex=0;
foreach(DataColumn col in table.Columns)
{
colIndex++;
excel.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString();
}
}
excel.Visible=false;
excel.ActiveWorkbook.SaveAs(strExcelFileName + ".XLS",
Excel.XlFileFormat.xlExcel9795, null, null, false,
false, Excel.XlSaveAsAccessMode.xlNoChange, null, null, null, null,null);
//wkbNew.SaveAs strBookName
//excel.Save(strExcelFileName);
excel.Quit();
excel=null;
GC.Collect();//垃圾回收
}
#endregion #region 从XML导入到Dataset /**//// <summary>
/// 从选择的XML文件导入
/// </summary>
/// <returns>DataSet</returns>
public DataSet ImportFromXML()
{
DataSet ds=new DataSet();
System.Windows.Forms.OpenFileDialog openFileDlg=new System.Windows.Forms.OpenFileDialog();
openFileDlg.DefaultExt="xml";
openFileDlg.Filter= "xml文件 (*.xml)|*.xml";
if (openFileDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
try{ds.ReadXml(openFileDlg.FileName,System.Data.XmlReadMode.ReadSchema);}
catch{}
return ds;
}
/**//// <summary>
/// 从指定的XML文件导入
/// </summary>
/// <param name="strFileName">XML文件名</param>
/// <returns></returns>
public DataSet ImportFromXML(string strFileName)
{
if (strFileName=="")
return null;
DataSet ds=new DataSet();
try{ds.ReadXml(strFileName,System.Data.XmlReadMode.ReadSchema);}
catch{}
return ds;
}
#endregion #region 从DataSet导出到XML
/**//// <summary>
/// 导出指定的XML文件
/// </summary>
/// <param name="ds">要导出的DataSet</param>
/// <param name="strXMLFileName">要导出的XML文件名</param>
public void ExportToXML(DataSet ds,string strXMLFileName)
{
if (ds.Tables.Count==0 || strXMLFileName=="") return;
doExportXML(ds,strXMLFileName);
}
/**//// <summary>
/// 导出用户选择的XML文件
/// </summary>
/// <param name="ds">DataSet</param>
public void ExportToXML(DataSet ds)
{
System.Windows.Forms.SaveFileDialog saveFileDlg=new System.Windows.Forms.SaveFileDialog();
saveFileDlg.DefaultExt="xml";
saveFileDlg.Filter= "xml文件 (*.xml)|*.xml";
if (saveFileDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
doExportXML(ds,saveFileDlg.FileName);
} /**//// <summary>
/// 执行导出
/// </summary>
/// <param name="ds">要导出的DataSet</param>
/// <param name="strExcelFileName">要导出的XML文件名</param>
private void doExportXML(DataSet ds,string strXMLFileName)
{
try
{ds.WriteXml(strXMLFileName,System.Data.XmlWriteMode.WriteSchema );}
catch(Exception ex)
{System.Windows.Forms.MessageBox.Show(ex.Message,"Errol") ;}
} #endregion
}}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Filter = "Excel files (*.xls)|*.xls";
dlg.Multiselect = false;
if (dlg.ShowDialog() == DialogResult.OK)
{
string FilePath = dlg.FileName;
BindingSource DataBinding = new BindingSource(this.fSampleDataTable(FilePath), null);
this.dataGridView1.DataSource = DataBinding;
}
}
}
private DataTable fSampleDataTable(string FilePath)
{
string connection = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = "+FilePath+";Extended Properties=Excel 8.0";
OleDbConnection thisconnection = new OleDbConnection(connection);
thisconnection.Open();
DataTable schemaTable = thisconnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
string table = schemaTable.Rows[0][2].ToString().Trim();//获取Excel的表名,默认值是sheet1
string command = "select * from ["+table+"]";
OleDbDataAdapter adapter = new OleDbDataAdapter(command, thisconnection);
DataSet ds = new DataSet();
adapter.Fill(ds, table);
thisconnection.Close();
DataTable MyNewTable = new DataTable();
foreach (DataRow Row in ds.Tables[table].Rows)
{
if (Row[0].ToString().Trim().StartsWith("7"))
{
MyNewTable.Merge(MyGetTableMethod("t_StoreAndSale", Row[0].ToString().Trim()));
}
/*else
{
MyNewTable.Merge(MyGetTableMethod("t_AI", Row[0].ToString().Trim()));
}*/
}
return MyNewTable;
}
private DataTable MyGetTableMethod(string ProcName,string ProcParameterValue)
{
string connection = "Server=192.100.3.3;Database=AIS20090330165131;uid=sa;pwd=;";
SqlConnection thisconntion = new SqlConnection(connection);
SqlCommand cmd = thisconntion.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = ProcName;
cmd.CommandTimeout = 0;
SqlParameter parameter = new SqlParameter("@FFullNumber", SqlDbType.VarChar, 40);
parameter.Direction = ParameterDirection.Input;
parameter.Value = ProcParameterValue;
cmd.Parameters.Add(parameter);
SqlDataAdapter Adapter = new SqlDataAdapter();
Adapter.SelectCommand = cmd;
DataSet ds = new DataSet();
Adapter.Fill(ds);
return ds.Tables[0];
}
}
}