111,123
社区成员
发帖
与我相关
我的任务
分享
public class Files
{
private string _FileName;
private int _FileSize;
private string _Suffix;
public Files(string FileName, int FileSize, string SortName)
{
this._FileName = FileName;
this._FileSize = FileSize;
this._Suffix = SortName;
}
public string FileName
{
get { return _FileName; }
set { _FileName = value; }
}
public int FileSize
{
get { return _FileSize; }
set { _FileSize = value; }
}
public string Suffix
{
get { return _Suffix; }
set { _Suffix = value; }
}
}
private List<int> listSize = new List<int>(new int[] { 10, 179, 22, 20, 24, 21, 21, 30, 20, 1149 });//表记录列表
private List<string> TableNames = new List<string>(new string[] { "u_DZDA", "u_JNJML", "u_KJJNJML", "u_JJWJ", "u_SBWJ", "u_CPWJ", "u_ZPJNJML", "u_ZPJHZL", "u_SXDA", "u_GDWJML" }); //表列表
private void Insert()
{
List<int> getJLID = new List<int>();
List<Files> GetFile = GetFiles();
string strConn = "Data Source=localhost;DataBase=FH_GSZDY;User ID=sa;Password=";
SqlConnection dbConn = new SqlConnection(strConn);
int count = listSize.Count;
int k = 0;
for (int i = 0; i < count; i++)
{
for (int j = k; j < k+listSize[i]; j++)
{
string xywm = "sdafoigjfgjojwnd" +(j+1);
string time = DateTime.Now.ToString();
string strSql = "select id from " + TableNames[i]; //查询出所有表的所有id
DataSet ds = SqlHelper.ExecuteDataset(dbConn, CommandType.Text, strSql);
DataTable dt = ds.Tables[0];
for (int z = 0; z < dt.Rows.Count; z++)
{
string str = dt.Rows[z][0] + "\n";
getJLID.Add(Convert.ToInt32(str));
} //问题就处在这里,我想把getJLID遍历后插入tYWXX表的JLID字段中,但这样写只能取出最后一个,不知道要怎么写?
string sql = sql = string.Format("insert into tYWXX(BM,JLID,XYWM,JYWM,WJDX,WJKZM,UID,YWLJ,SCSJ,WJLB) values('" + TableNames[i] + "','" + getJLID[z] + "','" + xywm + "','" + GetFile[j].FileName + "','" + GetFile[j].FileSize + "','" + GetFile[j].Suffix + "',10000,'/2009/0000/','" + time.ToString() + "',1)"); //“z”索引不能获取,放入for循环中,插入很多重复的
SqlHelper.ExecuteNonQuery(dbConn, CommandType.Text, sql);
}
k += listSize[i];
}
}
private List<Files> GetFiles() //获取文件名,文件大小,文件后缀名
{
List<Files> listFiles = new List<Files>();
DirectoryInfo Dir = new DirectoryInfo("E:\\3万页");
try
{
foreach (FileInfo f in Dir.GetFiles("*.*"))
{
string strFileExtention = Path.GetExtension(f.ToString());
Files Files = new Files(f.ToString(), Convert.ToInt32(f.Length), strFileExtention);
listFiles.Add(Files);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
return listFiles;
}
private void Insert()
{
List<int> getJLID = new List<int>();
List<Files> GetFile = GetFiles();
string strConn = "Data Source=localhost;DataBase=FH_GSZDY;User ID=sa;Password=";
SqlConnection dbConn = new SqlConnection(strConn);
int count = listSize.Count;
int k = 0;
for (int i = 0; i < count; i++)
{
string strSql = "select id from " + TableNames[i];
DataSet ds = SqlHelper.ExecuteDataset(dbConn, CommandType.Text, strSql);
DataTable dt = ds.Tables[0];
for (int z = 0; z < dt.Rows.Count; z++)
{
string str = dt.Rows[z][0] + "\n";
getJLID.Add(Convert.ToInt32(str));
}
for (int j = k; j < k+listSize[i]; j++)
{
string xywm = "sdafoigjfgjojwnd" + (j + 1);
string time = DateTime.Now.ToString();
string sql = string.Format("insert into tYWXX(BM,JLID,XYWM,JYWM,WJDX,WJKZM,UID,YWLJ,SCSJ,WJLB) values('" + TableNames[i] + "','" + getJLID[j] + "','" + xywm + "','" + GetFile[j].FileName + "','" + GetFile[j].FileSize + "','" + GetFile[j].Suffix + "',10000,'/2009/0000/','" + time.ToString() + "',1)");
SqlHelper.ExecuteNonQuery(dbConn, CommandType.Text, sql);
}
k += listSize[i];
}
}
for (int i = 0; i < count; i++)
{
for (int j = k; j < k+listSize[i]; j++)
{
string xywm = "sdafoigjfgjojwnd" +(j+1);
string time = DateTime.Now.ToString();
string strSql = "select id from " + TableNames[i];
DataSet ds = SqlHelper.ExecuteDataset(dbConn, CommandType.Text, strSql);
DataTable dt = ds.Tables[0];
for (int z = 0; z < dt.Rows.Count; z++)
{
string str = dt.Rows[z][0] + "\n";
getJLID.Add(Convert.ToInt32(str));
string sql = sql = string.Format("insert into tYWXX(BM,JLID,XYWM,JYWM,WJDX,WJKZM,UID,YWLJ,SCSJ,WJLB) values('" + TableNames[i] + "','" + getJLID[z] + "','" + xywm + "','" + GetFile[j].FileName + "','" + GetFile[j].FileSize + "','" + GetFile[j].Suffix + "',10000,'/2009/0000/','" + time.ToString() + "',1)"); //把添加语句写到循环里,会出现重复!然后就不知道怎么写了!
SqlHelper.ExecuteNonQuery(dbConn, CommandType.Text, sql);
}
}
k += listSize[i];
}
string str = dt.Rows[z][0] + "\n";
int whatyouwant Convert.ToInt32(str);
string sql = sql = string.Format("insert into tYWXX(BM,JLID,XYWM,JYWM,WJDX,WJKZM,UID,YWLJ,SCSJ,WJLB) values('" + TableNames[i] + "','" + whatyouwant + "','" + xywm + "','" + GetFile[j].FileName + "','" + GetFile[j].FileSize + "','" + GetFile[j].Suffix + "',10000,'/2009/0000/','" + time.ToString() + "',1)"); //把添加语句写到循环里,会出现重复!然后就不知道怎么写了!
SqlHelper.ExecuteNonQuery(dbConn, CommandType.Text, sql);
private void Insert()
{
List<int> getJLID = new List<int>();
List<Files> GetFile = GetFiles();
string strConn = "Data Source=localhost;DataBase=FH_GSZDY;User ID=sa;Password=";
SqlConnection dbConn = new SqlConnection(strConn);
int count = listSize.Count;
int k = 0;
for (int i = 0; i < count; i++)
{
for (int j = k; j < k+listSize[i]; j++)
{
string xywm = "sdafoigjfgjojwnd" +(j+1);
string time = DateTime.Now.ToString();
string strSql = "select id from " + TableNames[i];
DataSet ds = SqlHelper.ExecuteDataset(dbConn, CommandType.Text, strSql);
DataTable dt = ds.Tables[0];
for (int z = 0; z < dt.Rows.Count; z++)
{
string str = dt.Rows[z][0] + "\n";
getJLID.Add(Convert.ToInt32(str));
string sql = sql = string.Format("insert into tYWXX(BM,JLID,XYWM,JYWM,WJDX,WJKZM,UID,YWLJ,SCSJ,WJLB) values('" + TableNames[i] + "','" + getJLID[z] + "','" + xywm + "','" + GetFile[j].FileName + "','" + GetFile[j].FileSize + "','" + GetFile[j].Suffix + "',10000,'/2009/0000/','" + time.ToString() + "',1)"); //把添加语句写到循环里,会出现重复!然后就不知道怎么写了!
SqlHelper.ExecuteNonQuery(dbConn, CommandType.Text, sql);
}
}
k += listSize[i];
}
}