简体   繁体   中英

How to access and/or modify the (sql)DataSource in code behind (ASP.net c#)?

To connect to my database I used the wizard to make SQLDataSource. But I need to access it in code behind, to store my data in the database. Does someone knows how I can do that?

I appreciate your help. This is the code:

<asp:SqlDataSource 

ID="MySqlDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:HELPDESK_OUTLOOKConnectionString3 %>" SelectCommand="SELECT 

hd_aanvraag_fase.aanvraag_id,

hd_statussen.status_omschrijving as status,

hd_melding_niveau_1.niveau_omschrijving AS niveau1_omschrijving,

aanvrager.werknemersnaam AS melder ,

hd_aanvragen.aanvraag_titel ,

hd_aanvragen.aanvraag_omschrijving,

hd_aanvraag_fase.fase_datum

FROM hd_aanvragen 

INNER JOIN hd_meldingen         ON hd_meldingen.melding_id      =  hd_aanvragen.melding_id

INNER JOIN hd_melding_niveau_1  ON  hd_melding_niveau_1.niveau1_id = hd_meldingen.niveau1_id

INNER JOIN hd_melding_niveau_2  ON  hd_melding_niveau_2.niveau2_id = hd_meldingen.niveau2_id

INNER JOIN hd_aanvraag_fase     ON hd_aanvraag_fase.aanvraag_id =  hd_aanvragen.aanvraag_id

INNER JOIN hd_statussen         ON hd_statussen.status_id     =  hd_aanvraag_fase.status_id

INNER JOIN  hd_werknemers AS oplosser    ON oplosser.werknemer_Id    =  hd_aanvraag_fase.werknemer_Id

INNER JOIN hd_werknemers  AS aanvrager    ON aanvrager.werknemer_Id    =  hd_aanvragen.werknemer_Id

WHERE hd_statussen.status_id = 15

ORDER BY hd_aanvragen.aanvraag_id ,  hd_statussen.status_id"></asp:SqlDataSource>

Do you need to get the SQLDS data in something like a DataTable to see on code your data? or you just need to get data back on the DB?

Although I give you two useful links that can help you out in both situations:

1) http://www.dotnetspider.com/resources/7333-How-Extract-data-from-SQLDataSource-Data.aspx

DataView dv = new DataView();
DataTable dt = new DataTable();
dv = mySQLDataSource.Select(DataSourceSelectArguments.Empty) as DataView;
dt = dv.ToTable();

now on dt you have your data

2) http://www.c-sharpcorner.com/UploadFile/raj1979/SqlDataSource10032008142537PM/SqlDataSource.aspx

Working with sqldatasource on .net 3.5

Hope that can help

If you give the datasource an ID, in the markup code:

<SqlDataSource ID="MyDatasource" .../>

you should be able to access it from code behind.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM