asp.net和c#不能解决的相同问题 [英] same problem which is not solved with the help of asp.net and c#

查看:54
本文介绍了asp.net和c#不能解决的相同问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,先生,在代码odbccommand替换为sqlcommand的情况下,错误已删除,调试后代码中没有错误,但是问题是当我运行应用程序并且应用程序成功运行(在运行时)时,当按钮是单击(例如,将其放置在default.aspx中)然后检查数据库(将其放置在sql express中),该数据库中没有创建表.请先生解决我的问题.按钮是:

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先生,如果您解决了我的问题,请给我发送电子邮件(详细解决方案,因为我可以轻松地理解您的解决方案).我的电子邮件是[REMOVED] yahoo.com.谢谢SIR

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

推荐答案

您是否已经在以下位置尝试了答复中的建议(删除了多余的括号): ^ ]

另外,我认为在上一个仍处于活动状态时再次发布相同的问题并不是正确的方法.
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.


这篇关于asp.net和c#不能解决的相同问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆