Ciao a tutti,
dovrei popolare una dropdownlist col contenuto della prima colonna
(nome) di una tabella mysql. Vi posto il codice che ho messo a punto
codice:
protected void Page_Load(object sender, EventArgs e)
{
MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlDataAdapter myda;
DataSet ds = new DataSet();
string myConnectionString =
System.Configuration.ConfigurationManager.ConnectionStrings["db_connection1"].ConnectionString;
conn = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString);
conn.Open();
MySqlCommand cmd = new MySqlCommand(myConnectionString, conn);
MySqlDataReader rdr = cmd.ExecuteReader();
// ora preparo la query da eseguire come comando SQL
myda = new MySqlDataAdapter("SELECT nome FROM listadb", conn);
myda.Fill(ds, "nome");
DropDownList1.DataSource = rdr;
DropDownList1.DataBind();
// chiudo la connessione
conn.Close();
}
pagina aspx
codice:
<asp: DropDownList ID="DropDownList1" runat="server">
</asp: DropDownList>
visual studio mi dà questo errore:
MySql.Data.MySqlClient.MySqlException was unhandled by user code
Message="You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Datasource=localhost;Database=kfdb;uid=kingadmin; pwd=kpass' at line 1"
Source="MySql.Data"
ErrorCode=-2147467259
Number=1064
StackTrace:
in MySql.Data.MySqlClient.MySqlStream.OpenPacket()
in MySql.Data.MySqlClient.NativeDriver.ReadResult(UIn t64& affectedRows, Int64& lastInsertId)
in MySql.Data.MySqlClient.MySqlDataReader.GetResultSe t()
in MySql.Data.MySqlClient.MySqlDataReader.NextResult( )
in MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( CommandBehavior behavior)
in MySql.Data.MySqlClient.MySqlCommand.ExecuteReader( )
in controlpanel_wavelet.Page_Load(Object sender, EventArgs e) in c:\Users\Paul\Desktop\Sito per tirocinio\controlpanel_wavelet.aspx.cs:riga 37
in System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e)
in System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender, EventArgs e)
in System.Web.UI.Control.OnLoad(EventArgs e)
in System.Web.UI.Control.LoadRecursive()
in System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
Qualcuno mi può dare una mano?
Grazie