4

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>
1
  • If you can post some of your code then we may understand more of what you are trying to do. Commented Mar 3, 2011 at 12:44

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

2 Comments

I use a gridview and to display data in the gridview, I used the wizard to make my SqlDataSource. Now I need to know how I can access/modify SqlDataSource programmatically.
dv = (System.Data.DataView)SqlDataSource1.Select(System.Web.UI.DataSourceSelectArguments.Empty);
1

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

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

you should be able to access it from code behind.

2 Comments

To "store data in database" using your SqlDataSource, you need to deifine an UpdateCommand, just like you did a SelectCommand. Check: asp.net/data-access/tutorials/… and scroll down just below Figure 8 where they have an example for this. (A good read for more info on SqlDataSource.)
But I ask you how to modify SqlDataSource programmatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.