Click here to Skip to main content
15,921,884 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello sir,In code odbccommand replace by sqlcommand,errors are removed,there is no error in the code after debugging but the problem is that when i run the application and application run successfully (in run time),when the button is clicked(which is placed in the default.aspx,for example)then i check the database(which is placed in the sql express)there is no table created in that database.Please sir solve my problem.The code writtten in c# behind the button is that:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//using PractiseWeb.DataSet1TableAdapters;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Diagnostics;
using System.ComponentModel;
using System.Text;
using System.Data.SqlClient;
using System.Data.Odbc;
using ADOX;
using ADODB;

public partial class _Default : System.Web.UI.Page 
{
      SqlConnection conn;
      SqlCommand cmd;
    string connectionString = ConfigurationManager.ConnectionStrings["gameConnectionString"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try 
{
   conn = new SqlConnection(connectionString);
  if (!(conn.State == ConnectionState.Open)) 
    { 
        conn.Open(); 
    } 
    string sql = "CREATE TABLE mySchoolRecord(StudentId INTEGER CONSTRAINT PkeyMyId PRIMARY KEY,"
    + "Name CHAR(50)," + "Address CHAR(255)," + "Contact INTEGER));"; 
    cmd = new SqlCommand(sql,conn);
    cmd.ExecuteNonQuery(); 
    sql = "INSERT INTO mySchoolRecord (StudentId, Name,Address,Contact) VALUES (1, 'Mr. Manish', " + " 'Sector-12,Noida', 2447658  );";
    cmd = new SqlCommand(sql,conn);
    cmd.ExecuteNonQuery(); 
    sql = "INSERT INTO mySchoolRecord (StudentId, Name,Address,Contact) VALUES (2, 'Mr. Ravi', " + " 'New Delhi', 2584076521   );"; 
    cmd = new SqlCommand(sql,conn);
    cmd.ExecuteNonQuery();
    sql = "INSERT INTO mySchoolRecord (StudentId, Name,Address,Contact) VALUES (3, 'Mr. Peter', " + " 'United States', 25684124  );"; 
    cmd = new SqlCommand(sql,conn);
    cmd.ExecuteNonQuery(); 

    if (conn.State == ConnectionState.Open) 
    { 
        conn.Close(); 
    } 
 
} 
catch (Exception ex) 
{ 
   Console.WriteLine(ex); 
} 
    }
}
plz sir email me if you solve my problem(solution in detail beause i can easily understand your solution).My email is [REMOVED]yahoo.com.THANKS SIR
Posted
Updated 20-Mar-11 21:52pm
v3
Comments
Wendelius 21-Mar-11 3:53am    
Don't include your email address in the post. When someone replies your question you will get an email message automatically from the forum so there's no need of revealing the address you use.

1 solution

Did you already try the suggestion in the reply (removing the extra parenthesis) over here: if the user click on button then the database table is created in database(sql express) through asp.net with c sharp,how can do?[^]

Also I think that posting the same question again while the previous one is still active isn't the correct way to go.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900