i someone had teach me how to write a query in datatable. however i need to get the data out from my database rather than the data table. can someone teach me how should i do it?
esp at the first like... like DataTable dt = GetFilledTable()
since i already have set of data in my preset table i should be getting data from SqlDataSource1 right ( however i am writing this in my background code or within <script></script>
so can anyone help me?
protected void lnkRadius_Click(object sender, EventArgs e)
{
DataTable dt = GetFilledTable();
double radius = Convert.ToDouble(txtRadius.Text);
decimal checkX = (decimal)dt.Rows[0]["Latitude"];
decimal checkY = (decimal)dt.Rows[0]["Longitude"];
// expect dt[0] to pass - as this is our check point
// We use for rather than fopreach because the later does not allow DELETE during loop execution
for(int index=0; index < dt.Rows.Count; index++)
{
DataRow dr = dt.Rows[index];
decimal testX = (decimal)dr["Latitude"];
decimal testY = (decimal)dr["Longitude"];
double testXzeroed = Convert.ToDouble(testX -= checkX);
double testYzeroed = Convert.ToDouble(testY -= checkY);
double distance = Math.Sqrt((testXzeroed * testXzeroed) + (testYzeroed * testYzeroed));
// mark for delete (not allowed in a foreach - so we use "for")
if (distance > radius)
dr.Delete();
}
// accept deletes
dt.AcceptChanges();
GridView1.DataSource = dt.DefaultView;
GridView1.DataBind();
}
should start with
SqlDataSource1.SelectCommand = "SELECT [id], [title], [largeimage], [imageTakenAt], [imageLon], [imageLat], [notes] FROM [images]";
SqlDataSource1.DataBind;
or something like that?
|||Hi,
I would suggest you start from learning ADO.NET. You will learn how to write a query with SqlCommand, and use SqlDataAdapter to fill a DataTable.
Please start from the following link:
http://msdn2.microsoft.com/en-us/data/aa937699.aspx
HTH. If this does not answer your question, please feel free to mark the post as Not Answered and reply. Thank you!
No comments:
Post a Comment