burattif Posted August 29, 2003 Posted August 29, 2003 My code Hidden code in C# is: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace scuoleusr { /// <summary> /// Summary description for WebForm5. /// </summary> public class WebForm5 : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox Pippo; protected System.Web.UI.WebControls.Button Button1; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Pippo.TextChanged += new System.EventHandler(this.TextBox1_TextChanged); this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void TextBox1_TextChanged(object sender, System.EventArgs e) { } private void Button1_Click(object sender, System.EventArgs e) { SqlConnection connection = new SqlConnection("server=sqlservdida.csr.unibo.it;Trusted_Connection=false;database=scuole_usr;uid=redazioneusr_db;pwd=********"); try { connection.Open(); SqlCommand command = new SqlCommand("insert into burattif.NumeriProva (Numeri) " + "values ('"& Pippo.Text &"')", connection); command.ExecuteNonQuery(); } catch (Exception) { } finally { connection.Close(); } } } } The connection to SQLServer DB is ok .....but i can insert the record in the database! "Pippo" is ID of a TextBox. Help me, please. Francesco Quote
Gladimir Posted August 29, 2003 Posted August 29, 2003 A Chance... I'm going to take a stab and suggest putting brackets ([]) around the word Numeri in your INSERT statement. SqlCommand command = new SqlCommand("insert into burattif.NumeriProva ([Numeri]) " + "values ('"& Pippo.Text &"')", connection); Quote Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte
*Experts* Nerseus Posted August 29, 2003 *Experts* Posted August 29, 2003 Can you run this INSERT in Query Analyzer? Should look something like : insert into burattif.NumeriProva (Numeri) values ('valuehere') Unless your table NumeriProva is owned by user burattif, this might give you an error that the table NumeriProva can't be found. Also, you seem to be freely mixing "&" and "+" to do string concats. Freedom is good but mixing the two styles in the same line of code might not be so good :) (And, I didn't even think that would have compiled since it looks like you're using C# - I thought the "&" string concat operator was for VB). -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
burattif Posted September 1, 2003 Author Posted September 1, 2003 Thaks! I have corrected the code. Now it's ok. Sorry for my bad english. Francesco private void Button1_Click(object sender, System.EventArgs e) { SqlConnection connection = new SqlConnection("server=sqlservdida.csr.unibo.it;Trusted_Connection=false;database=scuole_usr;uid=redazioneusr_db;pwd=!20usr03!"); try { connection.Open(); SqlCommand command = new SqlCommand("insert into NumeriProva ([Numeri]) " + "values ('"+ Causio.Text +"')", connection); command.ExecuteNonQuery(); } catch (Exception) { } finally { connection.Close(); } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.