EDN Admin
Well-known member
I have an application which import log files into the sql database.
When debug it it gives me the following error. The parameterized query (@column1 nvarchar(4000),@column2 time(7),@column3 nvarchar(4000 expects the parameter @column1, which was not supplied.
My code is below. try
{
thisConnection.Open();
nonqueryCommand.CommandText = "INSERT INTO Table_2 VALUES (@column1,@column2,@column3,@column4,@column5,@column6,@column7,@column8,@column9,@column10,@column11,@column12,@column13,@column14)";
nonqueryCommand.Parameters.Add(new SqlParameter("@column1", SqlDbType.NVarChar, 4000)); //
nonqueryCommand.Parameters.Add(new SqlParameter("@column2", SqlDbType.Time));
nonqueryCommand.Parameters.Add(new SqlParameter("@column3", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column4", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column5", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column6", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column7", SqlDbType.BigInt));
nonqueryCommand.Parameters.Add(new SqlParameter("@column8", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column9", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column10", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column11", SqlDbType.BigInt));
nonqueryCommand.Parameters.Add(new SqlParameter("@column12", SqlDbType.BigInt));
nonqueryCommand.Parameters.Add(new SqlParameter("@column13", SqlDbType.BigInt));
nonqueryCommand.Parameters.Add(new SqlParameter("@column14", SqlDbType.BigInt));
try
{
var txtFiles = Directory.EnumerateFiles(sourcePath, "*.log");
if (txtFiles!=null)
{
foreach (string currentFile in txtFiles)
{
string fileName = currentFile.Substring(sourcePath.Length);
string[] allLines = File.ReadAllLines(currentFile);
{
String[] itemss = (File.ReadLines(currentFile)).Where(x => !x.StartsWith("#", StringComparison.CurrentCulture) && x.Contains("GET") && !x.Contains("SP_") && !x.Contains("SP_Admin") && (x.Contains(".pp") || x.Contains(".PP") || x.Contains(".do") || x.Contains(".swf") || x.Contains(".zip") || x.Contains(".ZIP") || x.Contains(".DO") || x.Contains(".Do") || x.Contains(".MP") || x.Contains(".mp") || x.Contains(".xl") || x.Contains(".XL") || x.Contains(".pdf") || x.Contains(".PDF") || x.Contains(".Mp") || x.Contains(".Mp3") || x.Contains(".Mp4") || x.Contains(".mp3") || x.Contains(".MP3") || x.Contains(".MP4")) && !x.Contains(".dll") && !x.Contains(".aspx") && !x.Contains("/_layouts/ExportOptionsPopup.aspx") && !x.Contains("/_layouts/MoveDocumentPopup.aspx")).ToArray();
//String[] itemss = (File.ReadLines(currentFile)).Where(x => !x.StartsWith("#", StringComparison.CurrentCulture)).ToArray();
for (int i = 0; i < itemss.Length; i++)
{
string[] items = itemss.Split(new char[] { });
if (items[7] == "-" || items[7].Contains("SP_") || items[7].Contains("sp") || items[5].Contains(".pp") || items[5].Contains(".do") || items[5].Contains(".xl") || items[5].Contains(".pdf"))
continue;
Console.WriteLine(itemss);
for (
int j = 0; j < items.Length; j++)
{
SqlParameter sparam = new SqlParameter("@column" + (j + 1), items[j]);
nonqueryCommand.ExecuteNonQuery();
}
nonqueryCommand.ExecuteNonQuery();
}
}
Directory.Move(currentFile, Path.Combine(targetPath, fileName));
}
}
}
finally
{
thisConnection.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Thanks in advance.
KAdir
View the full article
When debug it it gives me the following error. The parameterized query (@column1 nvarchar(4000),@column2 time(7),@column3 nvarchar(4000 expects the parameter @column1, which was not supplied.
My code is below. try
{
thisConnection.Open();
nonqueryCommand.CommandText = "INSERT INTO Table_2 VALUES (@column1,@column2,@column3,@column4,@column5,@column6,@column7,@column8,@column9,@column10,@column11,@column12,@column13,@column14)";
nonqueryCommand.Parameters.Add(new SqlParameter("@column1", SqlDbType.NVarChar, 4000)); //
nonqueryCommand.Parameters.Add(new SqlParameter("@column2", SqlDbType.Time));
nonqueryCommand.Parameters.Add(new SqlParameter("@column3", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column4", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column5", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column6", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column7", SqlDbType.BigInt));
nonqueryCommand.Parameters.Add(new SqlParameter("@column8", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column9", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column10", SqlDbType.NVarChar, 4000));
nonqueryCommand.Parameters.Add(new SqlParameter("@column11", SqlDbType.BigInt));
nonqueryCommand.Parameters.Add(new SqlParameter("@column12", SqlDbType.BigInt));
nonqueryCommand.Parameters.Add(new SqlParameter("@column13", SqlDbType.BigInt));
nonqueryCommand.Parameters.Add(new SqlParameter("@column14", SqlDbType.BigInt));
try
{
var txtFiles = Directory.EnumerateFiles(sourcePath, "*.log");
if (txtFiles!=null)
{
foreach (string currentFile in txtFiles)
{
string fileName = currentFile.Substring(sourcePath.Length);
string[] allLines = File.ReadAllLines(currentFile);
{
String[] itemss = (File.ReadLines(currentFile)).Where(x => !x.StartsWith("#", StringComparison.CurrentCulture) && x.Contains("GET") && !x.Contains("SP_") && !x.Contains("SP_Admin") && (x.Contains(".pp") || x.Contains(".PP") || x.Contains(".do") || x.Contains(".swf") || x.Contains(".zip") || x.Contains(".ZIP") || x.Contains(".DO") || x.Contains(".Do") || x.Contains(".MP") || x.Contains(".mp") || x.Contains(".xl") || x.Contains(".XL") || x.Contains(".pdf") || x.Contains(".PDF") || x.Contains(".Mp") || x.Contains(".Mp3") || x.Contains(".Mp4") || x.Contains(".mp3") || x.Contains(".MP3") || x.Contains(".MP4")) && !x.Contains(".dll") && !x.Contains(".aspx") && !x.Contains("/_layouts/ExportOptionsPopup.aspx") && !x.Contains("/_layouts/MoveDocumentPopup.aspx")).ToArray();
//String[] itemss = (File.ReadLines(currentFile)).Where(x => !x.StartsWith("#", StringComparison.CurrentCulture)).ToArray();
for (int i = 0; i < itemss.Length; i++)
{
string[] items = itemss.Split(new char[] { });
if (items[7] == "-" || items[7].Contains("SP_") || items[7].Contains("sp") || items[5].Contains(".pp") || items[5].Contains(".do") || items[5].Contains(".xl") || items[5].Contains(".pdf"))
continue;
Console.WriteLine(itemss);
for (
int j = 0; j < items.Length; j++)
{
SqlParameter sparam = new SqlParameter("@column" + (j + 1), items[j]);
nonqueryCommand.ExecuteNonQuery();
}
nonqueryCommand.ExecuteNonQuery();
}
}
Directory.Move(currentFile, Path.Combine(targetPath, fileName));
}
}
}
finally
{
thisConnection.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Thanks in advance.
KAdir
View the full article