Fetch return,将 nvarchar 转换为 bigint 时出错

Fetch return, error to convert nvarchar to bigint

我是 react-native 的新手,我尝试使用 GET 为登录页面发出获取请求。我与 WebService 交谈。当我对登录名和密码进行硬编码时,响应是正确的,但是如果我使用自己的变量,例如:this.state.login 我有以下错误:

System.Data.SqlClient.SqlException: Erreur de conversion du type de données nvarchar en bigint. à System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) à System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) à System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) à System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) à System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() à System.Data.SqlClient.SqlDataReader.get_MetaData() à System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) à System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) à System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) à System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) à System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) à System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) à System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) à System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) à System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) à System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) à dataClub.DSMembreTableAdapters.TAMembreBureau.GetDataForLogin(String LICI_NUMERO, String LICI_MDP, Nullable1 LOGINADMIN) dans C:\Users\vfelder\Documents\Visual Studio 2015\Projects\ClubOnline\dataClub\DSMembre.Designer.cs:ligne 3869 à ClubOnline.WebServices.AppliMobile.connexion(String p_login, String p_mdp) dans C:\Users\vfelder\Documents\Visual Studio 2015\Projects\ClubOnline\ClubOnline\WebServices\AppliMobile.asmx.cs:ligne 46

这是我的构造函数和提取请求:

constructor(){
    super();
    this.state = {
        login: '',
        password: ''
    }
}

userLogin(){
    fetch('myWebService?p_login=this.state.login&p_mdp=this.state.password',
        {
            method: 'GET',
            headers:{
                'Content-Type': 'application/x-www-form-urlencoded',
            },
        })
        .then(res => console.log(res));
}

这是与我的状态相关的 TextInput 和 Button:

                <TextInput
                    onChangeText={(text)=>this.setState({login: text})}
                    placeholder={'Identifiant'}
                    ref={"login"}
                    returnKeyType={'next'}
                    style={styles.input}
                    value={this.state.login}
                />
                <TextInput
                    editable={true}
                    onChangeText={(text)=>this.setState({password: text})}
                    placeholder={"Mot de passe"}
                    ref={'password'}
                    secureTextEntry={true}
                    style={styles.input}
                    value={this.state.password}
                />
                <Button
                    onPress={this.userLogin.bind(this)}
                    style={styles.buttonContainer}
                    title={"Connexion"}>
                </Button>

我尝试发出 post 请求或直接使用 XMLHttpRequest 但它总是一样的,如果我使用我自己的变量,则会生成此错误。我真的不知道我错过了什么。我希望尽可能具体。

您正在使用 this.state.loginthis.state.password 作为字符串,而不是将它们放在单引号中的值 '

fetch('your_url?p_login=this.state.login&p_mdp=this.state.password',

将此行更改为以下之一:


使用正确的单引号

fetch('your_url?p_login='+this.state.login+'&p_mdp='+this.state.password,

或:使用新的 ES6 语法 ${var}

fetch(`your_url?p_login=${this.state.login}&p_mdp=${this.state.password}`,

Note : I've replaced your url with your_url, so you can easily check the changes you need to make