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
Akhter HUssain
713
1.3k
103.2k
Importing Data From txt File into sql table
Nov 27 2018 10:20 PM
My Data Format is that
2018052605330002200009131
2018052604460002200009231
2018052604430001200009431
For understanding columns in sql table
(Date,20180526,time:0444,Status:0002,Empcode:2000091,MID:31)
here is my code, when i import data then error is coming of input string wast not in a correct format on this line
Int32 empcode = Convert.ToInt32(lines[i].Split(' ')[0].ToString());
whole code is mentioned below
protected
void
ReadDat(
object
sender, EventArgs e)
{
// string[] lines = File.ReadAllLines(Server.MapPath("FileUpload1.PostedFile.FileName"));
string
[] lines = File.ReadAllLines(Server.MapPath(FileUpload1.PostedFile.FileName));
for
(
int
i = 0; i < lines.Length; i++)
{
Int32 empcode = Convert.ToInt32(lines[i].Split(
' '
)[0].ToString());
DateTime Date = Convert.ToDateTime(lines[i].Split(
' '
)[1].ToString() +
" "
+ lines[i].Split(
' '
)[2].ToString());
int
Time = Convert.ToInt32(lines[i].Split(
' '
)[3]);
int
INOUT = Convert.ToInt32(lines[i].Split(
' '
)[4]);
int
MID = Convert.ToInt32(lines[i].Split(
' '
)[5]);
Insert (empcode,Date,Time,INOUT,MID);
}
}
public
void
Insert(
int
empcode, DateTime date,
int
TIme,
int
INOUT,
int
MID)
{
string
str = ConfigurationManager.ConnectionStrings[1].ConnectionString;
using
(SqlConnection con =
new
SqlConnection(str))
{
string
query =
"INSERT INTO HR VALUES("
+ empcode +
",'"
+ date +
"',"
+ TIme +
","
+ INOUT +
","
+ MID +
")"
;
using
(SqlCommand cmd =
new
SqlCommand(query, con))
{
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
}
Reply
Answers (
2
)
Identity, not rendering bootstrap css
Share pic with title on social media