大家好,我有我的数据库结构如下是否有可能到多个数据保存到数据库列
Field Type
FileHeader longblob
BatchHeader longblob
Entry longblob
BtchEntry longblob
FileControl longblob
我将要插入的数据如下
101 111111111 1111111111104021031A094101
52201 1 1 PPD1 110402110402 1111000020000001
6221110000251 00000000011 1 1 0111000020000001
822000000100111000020000000000000000000000011 111000020000001
52251 1 1 CCD1 110402110402 1111000020000002
6281110000251 00000000011 1 1 0111000020000002
822500000100111000020000000000010000000000001 111000020000002
9000006000001000000060066600012000000000003000000000003
你可以观察到有多行以5,6和8开始。我想将这些单独保存到我的表的相应列中。如果可以的话,是否可以提到最好的方法来做到这一点。如果不清楚请注明
我编写的代码是
using (StreamReader srRead = new StreamReader(filePath))
{
while (srRead.Peek() >= 0)
{
strLine = srRead.ReadLine();
if (strLine.StartsWith("1"))
{
strFileHeader = strLine;
}
if (strLine.StartsWith("5"))
{
strBatchHeader = strLine;
}
if (strLine.StartsWith("6"))
{
strEntry = strLine;
}
if (strLine.StartsWith("8"))
{
strBtchcntrl = strLine;
}
if (strLine.StartsWith("9"))
{
strFileCntrl = strLine;
}
}
string strQuery = "insert into tblfiles(FName, FData,FileHeader,BatchHeader,Entry,BtchEntry,FileControl) values (@_FName,@_FData,@_FileHeader,@_BtchHeader,@_EntryDets,@_BtchCntrl,@_FileCntrl)";
MySqlCommand cmd = new MySqlCommand(strQuery);
cmd.Parameters.Add("@_FName", MySqlDbType.VarChar).Value = filename;
cmd.Parameters.Add("@_FData", MySqlDbType.LongBlob).Value = bytes;
cmd.Parameters.Add("@_FileHeader", MySqlDbType.LongBlob).Value = strFileHeader;
cmd.Parameters.Add("@_BtchHeader", MySqlDbType.LongBlob).Value = strBatchHeader;
cmd.Parameters.Add("@_EntryDets", MySqlDbType.LongBlob).Value = strEntry;
cmd.Parameters.Add("@_BtchCntrl", MySqlDbType.LongBlob).Value = strBtchcntrl;
cmd.Parameters.Add("@_FileCntrl", MySqlDbType.LongBlob).Value = strFileCntrl;
InsertUpdateData(cmd);
但是,这将插入最新的数据库,但我想挽救每一条线路按我说
您已将此标记为“家庭作业”。你能否提供更多的作业细节(你正试图解决的问题)以及你现在拥有的**代码是否无效。我们不能指望你为你做功课。 – ChrisF 2011-04-06 11:35:51
@Chris:首先,我只想知道如何将多个数据插入到我的数据库中的指定列 – Dotnet 2011-04-06 11:36:59
为什么不直接通过结合参数化查询解析文件,您可以设置值列。 – Bobby 2011-04-06 11:40:09