null 不是对象 Sqlite + ReactNative 博览会 Typescript
我制作了登录页面,现在我尝试将简单的 user.js 替换为 Sqlite 数据库(react-native-sqlite-storage)。 当我使用数据库启动项目时,出现此错误。
我的代码
import {openDatabase} from 'react-native-sqlite-storage';
var db = openDatabase({name : 'UserDatabase.db'});
const SignInScreen = ({navigation}) => {
const [userName, setuserName] = useState();
const [userContact, setuserContact] = useState();
const [userAddress, setuserAddress] = useState();
let register_user = () =>
{
console.log(userName, userContact, userAddress);
db.transaction(function(tx)
{
tx.executeSql(
'INSERT INTO table_user(user_name, user_name, user_password) VALUES(?, ?,?)',
[userName, userContact, userAddress],
(tx, result) =>
{console.log('Result', result.rowAffected);
if (result.rowAffected > 0)
{
onPress: () => navigation.navigate('HomeScreen')
}
}
)
})}
//And Button
<TouchableOpacity
style={styles.signIn}
onPress={() => {register_user}}
>
<Text> Check //Here linegradient 1)</Text>
</TouchableOpacity>
I made login page and now i'm trying to replace simple user.js to Sqlite Database (react-native-sqlite-storage).
When i launch my project with database, i get this error.
My Code
import {openDatabase} from 'react-native-sqlite-storage';
var db = openDatabase({name : 'UserDatabase.db'});
const SignInScreen = ({navigation}) => {
const [userName, setuserName] = useState();
const [userContact, setuserContact] = useState();
const [userAddress, setuserAddress] = useState();
let register_user = () =>
{
console.log(userName, userContact, userAddress);
db.transaction(function(tx)
{
tx.executeSql(
'INSERT INTO table_user(user_name, user_name, user_password) VALUES(?, ?,?)',
[userName, userContact, userAddress],
(tx, result) =>
{console.log('Result', result.rowAffected);
if (result.rowAffected > 0)
{
onPress: () => navigation.navigate('HomeScreen')
}
}
)
})}
//And Button
<TouchableOpacity
style={styles.signIn}
onPress={() => {register_user}}
>
<Text> Check //Here linegradient 1)</Text>
</TouchableOpacity>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于在单独的文件中创建连接(必须在应用程序中创建)。
The problem consist from creating connection in separate file (must be create in App).