数据库连接并打开,但无法将文本框的数据插入数据表,执行后没有出错,求大神看看代码,哪里出了问题。

<?xml version="1.0" encoding="utf-8"?>
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="1400" height="900" backgroundFrameRate="60" title="单词记忆游戏机" backgroundColor="#FFFFFF">
fx:Script
<![CDATA[
import mx.controls.Alert;
import mx.utils.UIDUtil;
protected function SaveButton1_clickHandler(event:MouseEvent):void
{

            var conn:SQLConnection = new SQLConnection()
            var folder:File = File.applicationDirectory;
            var dbFile:File = folder.resolvePath("DaTa/nWord.db");
            var insertDt:SQLStatement=new SQLStatement();

            var idstr:String = UIDUtil.createUID();
            var namestr:String = ENname.text;
            var chinesestr1:String = CNname1.text;
            var chinesestr2:String = CNname2.text;
            var chinesestr3:String = CNname3.text;
            var chinesestr4:String = CNname4.text;
            var chinesestr5:String = CNname5.text;
            var chinesestr6:String = CNname6.text;
            var chinesestr7:String = CNname7.text;
            var chinesestr8:String = CNname8.text;
            var chinesestr9:String = CNname9.text;
            var chinesestr10:String = CNname10.text;

            //var insertSQL:String="INSERT INTO ziMuShunXu(id,name,chinese1,chinese2,chinese3,chinese4," +
            //"chinese5,chinese6,chinese7,chinese8,chinese9,chinese10) VALUES(:id,:name,:chinese1,:chinese2," +
            //":chinese3,:chinese4,:chinese5,:chinese6,:chinese7,:chinese8,:chinese9,:chinese10)";
            try
            {
                conn.open(dbFile);

                insertDt.sqlConnection = conn;
                insertDt.text = "INSERT INTO ziMuShunXu(id,name,chinese1,chinese2,chinese3,chinese4," +
                    "chinese5,chinese6,chinese7,chinese8,chinese9,chinese10) VALUES(:id,:name,:chinese1,:chinese2," +
                    ":chinese3,:chinese4,:chinese5,:chinese6,:chinese7,:chinese8,:chinese9,:chinese10)";
                insertDt.parameters[":id"]=idstr;
                insertDt.parameters[":name"]=namestr;
                insertDt.parameters[":chinese1"]=chinesestr1;
                insertDt.parameters[":chinese2"]=chinesestr2;
                insertDt.parameters[":chinese3"]=chinesestr3;
                insertDt.parameters[":chinese4"]=chinesestr4;
                insertDt.parameters[":chinese5"]=chinesestr5;
                insertDt.parameters[":chinese6"]=chinesestr6;
                insertDt.parameters[":chinese7"]=chinesestr7;
                insertDt.parameters[":chinese8"]=chinesestr8;
                insertDt.parameters[":chinese9"]=chinesestr9;
                insertDt.parameters[":chinese10"]=chinesestr10;
                insertDt.execute();

                trace("shujuchenggong"+dbFile.nativePath);

            }
            catch (error:SQLError)
            {
                trace("xingxi",error.message);
                trace("xiangqing",error.details);

            }

            Alert.show("已保存"+namestr+"及汉语意思","提示");
        }
    ]]>
</fx:Script>
<s:Label x="400" y="10" text="工作与爱好统一是最幸福的" color="#00000" fontSize="50" fontFamily="叶根友毛笔行书2.0版"/>
<s:Panel title="输入框" x="5" y="90" width="300" height="650" id="ShuRu">
    <s:Label x="20" y="10" text="请输入单词:" color="#00000" fontSize="20" fontFamily="宋体"/>
    <s:TextInput restrict="A-Z,a-z" x="148" y="10" id="ENname"/>
    <s:Label x="20" y="45" text="请输入汉意1:" color="#00000" fontSize="20" fontFamily="宋体"/>
    <s:TextInput restrict="a-z\.\,\{'[\u4e00-\u9fa5]'}" x="148" y="45" id="CNname1"/>
    <s:Label x="20" y="80" text="请输入汉意2:" color="#00000" fontSize="20" fontFamily="宋体"/>
    <s:TextInput x="148" y="80" id="CNname2"/>
    <s:Label x="20" y="115" text="请输入汉意3:" color="#00000" fontSize="20" fontFamily="宋体"/>
    <s:TextInput x="148" y="115" id="CNname3"/>
    <s:Label x="20" y="150" text="请输入汉意4:" color="#00000" fontSize="20" fontFamily="宋体"/>
    <s:TextInput x="148" y="150" id="CNname4"/>
    <s:Label x="20" y="185" text="请输入汉意5:" color="#00000" fontSize="20" fontFamily="宋体"/>
    <s:TextInput x="148" y="185" id="CNname5"/>
    <s:Label x="20" y="220" text="请输入汉意6:" color="#00000" fontSize="20" fontFamily="宋体"/>
    <s:TextInput x="148" y="220" id="CNname6"/>
    <s:Label x="20" y="255" text="请输入汉意7:" color="#00000" fontSize="20" fontFamily="宋体"/>
    <s:TextInput x="148" y="255" id="CNname7"/>
    <s:Label x="20" y="290" text="请输入汉意8:" color="#00000" fontSize="20" fontFamily="宋体"/>
    <s:TextInput x="148" y="290" id="CNname8"/>
    <s:Label x="20" y="325" text="请输入汉意9:" color="#00000" fontSize="20" fontFamily="宋体"/>
    <s:TextInput x="148" y="325" id="CNname9"/>
    <s:Label x="20" y="360" text="请输入汉意10:" color="#00000" fontSize="20" fontFamily="宋体"/>
    <s:TextInput x="148" y="360" id="CNname10"/>
    <s:Button x="200" y="550" label="保存" color="#fd0000" fontSize="15" width="50" height="30" click="SaveButton1_clickHandler(event)"/>
</s:Panel>
<s:Panel title="单词列表" x="320" y="90" width="1075" height="650" id="XianShi">

</s:Panel>
<fx:Declarations>
    <!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>

/s:WindowedApplication

2个回答

是的,但关闭与不关闭不影响,后来发现问题了问题的所在,其实数据已经存储进去了是数据库操作的第三方软件出了问题,换了一个就好了。

你的conn对象一直没关闭!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问