을 사용하여 DataTable 값이 일치하지 않습니다. 다음 코드는 다소 혼란스러운 예외입니다.SqlGeography 및 C#
public void BuildTable()
{
using (SqlConnection connection = new SqlConnection("Data Source=ylkx1ic1so.database.windows.net;Initial Catalog=hackathon;Persist Security Info=True;User ID=REDACTED;Password=REDACTED"))
{
SqlGeographyBuilder builder = createTestPoint();
SqlGeography myGeography = builder.ConstructedGeography;
connection.Open();
DataTable myTable = new DataTable();
using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM myTable", connection))
{
SqlCommandBuilder cb = new SqlCommandBuilder(adapter);
adapter.Fill(myTable);
myTable.Rows.Add(6, "Test", myGeography);
adapter.Update(myTable);
}
}
}
private SqlGeographyBuilder createTestPoint()
{
SqlGeographyBuilder builder = new SqlGeographyBuilder();
builder.SetSrid(4326);
builder.BeginGeography(OpenGisGeographyType.Point);
builder.BeginFigure(31, -85);
builder.EndFigure();
builder.EndGeography();
return builder;
}
라인 myTable.Rows.Add (6, "테스트"myGeography);이 어디 I "m 다음과 같은 예외가 점점 :.
Type of value has a mismatch with column typeCouldn't store <POINT (-85 31)> in placemark Column. Expected type is SqlGeography.
내가하지 않는 것은 내가이 시도 디버깅하는 동안이 실패 할 이유입니다 :
for (int i = 0; i < myTable.Columns.Count; i++)
{
Debug.WriteLine(myTable.Columns[i].DataType);
}
Debug.WriteLine(myGeography.GetType());
그리고 내 밖으로 넣어했다 :
System.Int32
System.String
Microsoft.SqlServer.Types.SqlGeography
Microsoft.SqlServer.Types.SqlGeography
그래서, 나는 확실히 SqlGeography 오브젝트를 취해 열에서 SqlGeography 객체를 넣어 노력하고있어.
그래도 작동 할 수 있으면 좋겠어. 그래도 DataTable. 이것은 좀 더 복잡한 것을하기위한 일종의 테스트 케이스이며,이 방법은 엉덩이에 고통이 될 것입니다. 감사합니다! – Pharylon