Hi im trying to connect to sql which i can do but i am then trying to use the sql to create a xml file for the output. I am using the below code but the connection is not working. protected void saveCurrentData(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["cellulant_ConnectionString"].ToString()); SqlDataAdapter adapt = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand("select * from Product", myConnection); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet td = new DataSet("Product"); da.Fill(td); td.WriteXml(Server.MapPath("temp\\temp.xml"), XmlWriteMode.WriteSchema); } Code (markup): i have the below code connecting and display the sql row i want to insert into the xml just fine <asp:GridView id="grdProducts" DataSourceID="spring11" Runat="server" /> <asp:SqlDataSource ID="spring11" runat="server" connectionstring="Data Source=xxxxxxx,14330;Initial Catalog=spring11;Persist Security Info=True;User ID=xxxxx; Password= xxxxxx" SelectCommand="SELECT * FROM Product"> </asp:SqlDataSource> Code (markup): any advice on how to process this
i am receiving the following error error CS0246: The type or namespace name 'SqlConnection' could not be found the asp tagged connection in the body works just fine its just the script section which throws this error
below is my script its in my main aspx page i think i might be adding this in wrong should i be doing this in the cs file ? <script runat="server"> using System.Data.SqlClient; protected void saveCurrentData(object sender, EventArgs e) { binddata(); } private void binddata() { SqlConnection sqlConnection = new SqlConnection("Data Source=xxxxxx,14330;Initial Catalog=xxxxxxx;Persist Security Info=True;User ID=xxxxx; Password= xxxxx"); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("Select * From Product", sqlConnection); DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet); dataSet.WriteXml(Server.MapPath("temp\\temp.xml"), XmlWriteMode.WriteSchema); } </script>