我想用数据集更新数据库中的列 [英] I want to update columns in a database with a dataset

查看:65
本文介绍了我想用数据集更新数据库中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新数据库表中的两列。



下面是我用来迭代数据网格以获取商店地址的代码。

在我用来搜索的数据库中使用方法GetGoogleSearch获取GPS坐标。



然后我从互联网上获取GPS坐标并将其放入数据表中。



我现在想要更新列并放置我找到的数据并更新列,因为它们当前设置为NULL,用于数据库中的坐标经度和纬度。



以下代码用于迭代并获得GPS坐标。

I want to update two columns in my database table.

Below is the code that I use to iterate through a datagrid to get addresses of shops.
In my database which I use to search for GPS coordinates using the method GetGoogleSearch.

I then get the GPS coordiates from the internet and I put them in a datatable.

I now want to update the columns and put that data I found and update columns as they are currently set to NULL for the coordinates Longitude and Latitude in the database.

Code is below for iterating and getting GPS coordinates is below.

private void btnMapStoreAddresses_Click(object sender, EventArgs e)
{

    AddressServiceData _AddressServiceData = new AddressServiceData();

    try
    {

        DataTable _PnPStoresListDataTable = new DataTable();
        string address = string.Empty;

        int GridRowCounnt = 0;
        GridRowCounnt = dgrgPnPStores.RowCount;


        for (int i = 0; i < GridRowCounnt; i++)
        {
             address = dgrgPnPStores.Rows[i].Cells[5].Value.ToString();
            _PnPStoresListDataTable = _AddressServiceData.GetGoogleSearch("", address + " South Africa", "", "");             
            

        }

}

推荐答案

创建存储过程" UpdateLatitude_Longitude"它接受三个名为Address,Latitude和Longitude的参数,并在该存储过程中更新该特定地址的列。

使用GetGoogleSearch方法获取纬度和经度值后调用此存储过程。您已经将纬度和经度存储在数据表中。因此,请使用数据表中的参数地址和纬度和经度值调用UpdateLatitude_Longitude,这将更新数据库中的值。
Create a stored procedure "UpdateLatitude_Longitude" which accepts three parameters called Address,Latitude and Longitude and in that stored procedure update the columns for that particular address.
Call this stored procedure once you get the Latitude and Longitude values using GetGoogleSearch method. you are already storing the latitude and longitude in a data table. so call the UpdateLatitude_Longitude with the params address and Latitude and Longitude values from the datatable, which will update the vales in the DB.


这篇关于我想用数据集更新数据库中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆