*.TXT
파일의 길이는 약 1 - 200 줄입니다. 각 줄은 City/Suburb의 이름 일 뿐이며이 파일의 각 줄을 데이터베이스에 삽입하려고합니다.줄 단위로 SQL Server CE 데이터베이스에 삽입합니다.
Try/Catch 블록은 작동하지 않았기 때문에 모두 넣었지만 예외가있을 경우 아무 것도 표시되지 않습니다.
db.Execute("insert into SuburbsPostCodesAndStates (Suburb, State) values (@0, @1)", "lol", "nsw");
내가이 라인을 삽입 사용하고 있음을 가지고있는 코드는 다음과 같습니다 :
@{
var message = "";
var db = Database.Open("SSSCCC");
try
{
if(File.Exists(Href("~/NSW.txt")))
{
string[] text = File.ReadAllLines(Href("~/NSW.txt"));
using (StringReader reader = new StringReader(text))
{
string line;
while ((line = reader.ReadLine()) != null)
{
db.Execute("insert into SuburbsPostCodesAndStates (Suburb, State) values (@0, @1)", line, "NSW");
}
}
}
}
catch(Exception exception)
{
message = exception.Message;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
@message
</body>
</html>
난 그냥이 줄을 한 번에 한 레코드를 삽입 할 수 있음을 확인했다 이 문제를 어떻게 해결할 수 있습니까?
아무런 도움이 필요하지 않습니다.
당신에게해결 감사합니다
@{
var message = "";
var db = Database.Open("SSSCCC");
try
{
if(File.Exists(Server.MapPath("NSW.txt")))
{
string[] text = File.ReadAllLines(Server.MapPath("NSW.txt"));
if(text.Length == 0) { throw new Exception("File does not contain any lines"); }
foreach(string line in text)
{
db.Execute("insert into SuburbsPostCodesAndStates (Suburb, State) values (@0, @1)", line, "NSW");
}
}
else
{
throw new Exception("File does not exist");
}
}
catch(Exception exception)
{
message = exception.Message;
}
}
@ p.campbell - WebMatrix와 함께 제공되는 SQL Server Compact를 사용하고 있습니다. – Arrow
어쩌면 별도의 삽입 문을 100 개 호출하는 대신 BULK INSERT를 고려해야합니다. –
WebMatrix SQL Compact DB에 대량 삽입 할 수 없습니다 (WebMatrix를 사용하지 않기로 결정한 이유입니다). 호스팅 회사에서 제공 한 것이지만 아직 할 수는 없습니다. _ – Arrow