I have a concurrent queue defined with a class object which holds 65000 records defined like below
ConcurrentQueue<Data> DataQueue = new ConcurrentQueue<Data>();
public class Data
{
public string Id { get; set; }
public string T { get; set; }
public string D { get; set; }
public string L { get; set; }
public string I { get; set; }
public string V { get; set; }
}
I am using following code to insert into db
public void InsertIntoDB()
{
using (cn = new SqlConnection(connectionString))
{
cn.Open();
Data item;
while (SpotDataQueue.Count > 0)
{
if (DataQueue.TryDequeue(out item))
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandText = @"INSERT INTO [TableName] ([WId], [L], [I], [V],[JId],[I],[DateTime]) VALUES (@WId, @l, @i, @v, @jid,@i,@dt)";
cm.Parameters.AddWithValue("WId", item.Id);
cm.Parameters.AddWithValue("@l", item.L);
cm.Parameters.AddWithValue("@i", item.I);
cm.Parameters.AddWithValue("@v", item.V);
cm.Parameters.AddWithValue("@jid", 1);
cm.Parameters.AddWithValue("@i", false);
cm.Parameters.AddWithValue("@dt", DateTime.Now);
cm.ExecuteNonQuery();
}
}
}
}
}
Table structure :
WId nvarchar(50) AllowNulls
L nvarchar(MAX) AllowNulls
I nvarchar(MAX) AllowNulls
V nvarchar(MAX) AllowNulls
JId int AllowNulls
I bit AllowNulls
DateTime datetime AllowNulls
How to convert my concurrent queue of type Data to a DATATABLE or DATAREADER to make SQLBULKCOPY possible ?
Thanks.