Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用vb.net在asp.net webforms中显示带有“是”或“否”的消息框?_Asp.net_Sql Server_Vb.net - Fatal编程技术网

如何使用vb.net在asp.net webforms中显示带有“是”或“否”的消息框?

如何使用vb.net在asp.net webforms中显示带有“是”或“否”的消息框?,asp.net,sql-server,vb.net,Asp.net,Sql Server,Vb.net,在将记录插入到表中之前,系统将首先检查此人的名字和姓氏是否已经存在。如果此人存在,则会出现一个带有“是”或“否”按钮的消息框,询问用户是否要继续插入记录。我已尝试以下代码: Imports ChurchMIS.Data Imports System Imports System.Collections.Generic Imports System.Data Imports System.Linq Imports System.Text.RegularExpressions Imports Sys

在将记录插入到表中之前,系统将首先检查此人的名字和姓氏是否已经存在。如果此人存在,则会出现一个带有“是”或“否”按钮的消息框,询问用户是否要继续插入记录。我已尝试以下代码:

Imports ChurchMIS.Data
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Linq
Imports System.Text.RegularExpressions
Imports System.Web
Imports System.Web.Security
Imports System.Data.SqlClient
Namespace ChurchMIS.Rules

Partial Public Class IndividualBusinessRules
    Inherits ChurchMIS.Data.BusinessRules

    ''' <summary>
    ''' This method will execute in any view for an action
    ''' with a command name that matches "SQL".
    ''' </summary>
    <Rule("r107")>  _
    Public Sub r107Implementation( _
                ByVal individualId As Nullable(Of Integer),  _
                ByVal firstName As String,  _
                ByVal lastName As String,  _
                ByVal dateOfBirth As Nullable(Of DateTime),  _
                ByVal addressTypeId As Nullable(Of Integer),  _
                ByVal suburb As String,  _
                ByVal streetAddress As String,  _
                ByVal postCode As Nullable(Of Integer),  _
                ByVal contactInfoTypeId As Nullable(Of Integer),  _
                ByVal contactNo As String,  _
                ByVal fullName As String,  _
                ByVal individualTypeId As Nullable(Of Integer),  _
                ByVal state As String,  _
                ByVal dateOfBaptism As Nullable(Of DateTime),  _
                ByVal dateOfTransfer As Nullable(Of DateTime),  _
                ByVal email As String,  _
                ByVal faithStatus As Nullable(Of Integer),  _
                ByVal noOfVisits As Nullable(Of Integer),  _
                ByVal name As String,  _
                ByVal name_1 As String,  _
                ByVal name_2 As String)
        'This is the placeholder for method implementation.
        Dim con As SqlConnection = New SqlConnection("Data     Source=CNEPHILS;Initial Catalog=ChurchMIS;User ID=sa;Password=Cn$phil$")

        Dim theQuery As String = "SELECT * FROM Individual WHERE  FirstName=@FirstName AND LastName=@LastName"
        Dim cmd1 As SqlCommand = New SqlCommand(theQuery, con)
        cmd1.Parameters.AddWithValue("@FirstName", firstName)
        cmd1.Parameters.AddWithValue("@LastName", lastName)

        Using reader As SqlDataReader = cmd1.ExecuteReader()
            If reader.HasRows Then
                ' person already exists
                    Dim result As Integer=

                Dim result As Integer = MessageBox.Show("message",  "caption", MessageBoxButtons.YesNoCancel)
                If result = DialogResult.Cancel Then
                    MessageBox.Show("Cancel pressed")
                ElseIf result = DialogResult.No Then
                    MessageBox.Show("No pressed")
                ElseIf result = DialogResult.Yes Then
                    Dim cmd As SqlCommand = New SqlCommand("exec  spInsertIndividual @FirstName,@LastName,@DateOfBirth,@Suburb,@StreetAddress,@PostCode,@State,@AddressTypeId,@ContactInfoTypeId,@ContactNo,@IndividualTypeId,@Email,@FaithStatus,@DateOfBaptism,@DateOfTransfer", con)
                    cmd.ExecuteNonQuery()
                    MsgBox("Records Successfully Added!", MsgBoxStyle.Information)
                End If
            Else
                ' person does not exist, add them
                Dim cmd As SqlCommand = New SqlCommand("exec spInsertIndividual @FirstName,@LastName,@DateOfBirth,@Suburb,@StreetAddress,@PostCode,@State,@AddressTypeId,@ContactInfoTypeId,@ContactNo,@IndividualTypeId,@Email,@FaithStatus,@DateOfBaptism,@DateOfTransfer", con)
                cmd.ExecuteNonQuery()
                MsgBox("Records Successfully Added!", MsgBoxStyle.Information)
            End If
        End Using

        con.Close()

    End Sub
End Class
End Namespace
导入管理信息系统数据
导入系统
导入System.Collections.Generic
导入系统数据
导入系统
导入System.Text.RegularExpressions
导入系统.Web
导入System.Web.Security
导入System.Data.SqlClient
名称空间管理信息系统规则
部分公共类IndividualBusinessRules
继承ChurchMIS.Data.BusinessRules
''' 
''此方法将在操作的任何视图中执行
“”的命令名与“SQL”匹配。
''' 
_
公共子系统实施(_
ByVal individualId可为空(整数)_
ByVal firstName作为字符串_
ByVal lastName作为字符串_
ByVal dateOfBirth可为空(日期时间)_
ByVal addressTypeId可为空(整数)_
比瓦尔郊区作为弦_
ByVal streetAddress作为字符串_
ByVal邮政编码可为空(整数)_
ByVal contactInfoTypeId可为空(整数)_
ByVal contactNo作为字符串_
ByVal fullName作为字符串_
ByVal individualTypeId可为空(整数)_
ByVal状态作为字符串_
ByVal dateOfBaptism可为空(日期时间)_
ByVal dateOfTransfer可为空(日期时间)_
ByVal电子邮件作为字符串_
ByVal faithStatus可为空(整数)_
ByVal noOfVisits可为空(整数)_
ByVal名称作为字符串_
ByVal name_1作为字符串_
ByVal名称(以字符串形式显示)
'这是方法实现的占位符。
Dim con As SqlConnection=New SqlConnection(“数据源=CNEPHILS;初始目录=ChurchMIS;用户ID=sa;密码=Cn$phil$”)
将查询设置为String=“SELECT*FROM Individual,其中FirstName=@FirstName和LastName=@LastName”
Dim cmd1 As SqlCommand=新SqlCommand(查询,con)
cmd1.Parameters.AddWithValue(“@FirstName”,FirstName)
cmd1.Parameters.AddWithValue(“@LastName”,LastName)
将读卡器用作SqlDataReader=cmd1.ExecuteReader()
如果reader.HasRows那么
“这个人已经存在了
将结果设置为整数=
Dim结果为整数=MessageBox.Show(“消息”、“标题”、MessageBox按钮。是否取消”)
如果结果=对话框结果。则取消
MessageBox.Show(“按取消键”)
ElseIf result=DialogResult.No然后
MessageBox.Show(“未按下”)
ElseIf result=对话框结果。那么是
Dim cmd As SqlCommand=New SqlCommand(“exec spInsertIndividual@FirstName、@LastName、@DateOfBirth、@郊区、@StreetAddress、@PostCode、@State、@AddressTypeId、@ContactNo、@IndividualTypeId、@Email、@FaithStatus、@dateofbatism、@DateOfTransfer”、con)
cmd.ExecuteNonQuery()
MsgBox(“已成功添加记录!”,MsgBoxStyle.Information)
如果结束
其他的
'人不存在,请添加他们
Dim cmd As SqlCommand=New SqlCommand(“exec spInsertIndividual@FirstName、@LastName、@DateOfBirth、@郊区、@StreetAddress、@PostCode、@State、@AddressTypeId、@ContactNo、@IndividualTypeId、@Email、@FaithStatus、@dateofbatism、@DateOfTransfer”、con)
cmd.ExecuteNonQuery()
MsgBox(“已成功添加记录!”,MsgBoxStyle.Information)
如果结束
终端使用
con.Close()
端接头
末级
结束命名空间
但是,我引发了一个错误“MessageBox未声明…保护级别”


希望有人能帮忙。谢谢

罗杰。我认为您的工作是在web应用程序中。尝试此操作,将此脚本添加到head标记内的.aspx页面中

<script type="text/javascript">
        function SomeMethod() {
            try {
                var result = true;
                var obj = {};
                obj.Firstname = $('#<%=txtfirstname.ClientID %>').val();
                obj.Lastname = $('#<%=txtlastname.ClientID %>').val();
                $.ajax({
                    type: "POST",
                    data: JSON.stringify(obj),
                    url: "yourformname.aspx/yourmethodname",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async:false,
                    success: function (response) {
                        if (response.d.toString() == "true") {
                                if (confirm("first name and last name of the person is already exists?")) {
                                    result = true;
                                    // insert the user name
                                }
                                else {
                                    result = false;

                                }
                        }
                        else {

                        }
                    },
                    failure: function (response) {
                        alert(response.d);
                    }
                });
            }
            catch (e) {
                alert(e);
            }
            return result;
        }
    </script>

函数方法(){
试一试{
var结果=真;
var obj={};
obj.Firstname=$('#').val();
obj.Lastname=$('#').val();
$.ajax({
类型:“POST”,
数据:JSON.stringify(obj),
url:“yourformname.aspx/yourmethodname”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
async:false,
成功:功能(响应){
if(response.d.toString()=“true”){
如果(确认(“此人的名字和姓氏已经存在?”){
结果=真;
//插入用户名
}
否则{
结果=假;
}
}
否则{
}
},
故障:功能(响应){
警报(response.d);
}
});
}
捕获(e){
警报(e);
}
返回结果;
}
在按钮单击事件中调用javascript函数。如果您正在使用RequiredFieldValidator进行验证,请使用Page_ClientValidate()以其他方式删除button onclick事件中的Page_ClientValidate()函数

<asp:Button ID="btnbutton" CssClass="Designclass" OnClientClick="if(Page_ClientValidate()) return SomeMethod();"
                                        runat="server" Text="Generate" />

在.aspx.vb页面中创建以下web方法

 <System.Web.Services.WebMethod()>
Public Shared Function Checkuserexists(ByVal Firstname As String, ByVal Lastname As String) As String
    'write your code for checking firstname and last name
     If exists > 0 Then
        Return true
    Else
        Return False
    End If
End Function
<代码