TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Avinash Verma
NA
3
929
Bulk text import into SQL server using C#
Mar 16 2018 5:47 AM
Hi,
I have the text file and want to use sqlbulk copy to load the data in to SQL using C#
using below code getting error- Column requires a valid DataType.
String strConnection = "Data Source=localhost;Initial Catalog=" + pname + ";Integrated Security=True";
String textConnString = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"text\"", fname);
DataTable dt = new DataTable();
string line = null;
int i = 0;
using (StreamReader sr = File.OpenText(fname))
{
while ((line = sr.ReadLine()) != null)
{
string[] data = line.Split(' ');
if (data.Length > 0)
{
if (i == 0)
{
foreach (var item in data)
{
DataColumn column;
column = new DataColumn();
column.DataType = System.Type.GetType("System.char");
dt.Columns.Add(new DataColumn());---->(getting error Column requires a valid DataType)
}
i++;
}
DataRow row = dt.NewRow();
row.ItemArray = data;
dt.Rows.Add(row);
}
}
}
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(strConnection))
{
bulkCopy.BulkCopyTimeout = 0;
bulkCopy.DestinationTableName = "dbo.AdmissionControl";
// Write from the source to the destination.
bulkCopy.WriteToServer(dt);
}
please support
Reply
Answers (
1
)
redirect from one page to another page
SQL update query to implement in c#