主题:SQL中为什么不能插入一条记录
con=new SqlConnection("Server=XIAOLINJUAN; database=FriendsDate;Uid=sa;Pwd=123456");
cmd=new SqlCommand(sql,con);
con.Open();
bool doredirect=true;
try
{
cmd.ExecuteNonQuery();
}
catch
{
doredirect=false;
this.lblMessage.Visible=true;
this.lblMessage.Text="[color=000080]Insert couldn't be performed.User name maybe already taken!";[/color] }
finally
{
con.Close();
}
if(doredirect==true)
Response.Redirect("Login.aspx");
}
else
lblMessage.Text="Fix the following errors and retry!";
}
}
}
为什么运行结果出现Insert couldn't be performed.User name maybe already taken!
cmd=new SqlCommand(sql,con);
con.Open();
bool doredirect=true;
try
{
cmd.ExecuteNonQuery();
}
catch
{
doredirect=false;
this.lblMessage.Visible=true;
this.lblMessage.Text="[color=000080]Insert couldn't be performed.User name maybe already taken!";[/color] }
finally
{
con.Close();
}
if(doredirect==true)
Response.Redirect("Login.aspx");
}
else
lblMessage.Text="Fix the following errors and retry!";
}
}
}
为什么运行结果出现Insert couldn't be performed.User name maybe already taken!