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));
- 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();
- }
- }
- }
- }
- }