建议输入的时候把单行元素分割“ ”(空格)改为“,” 当然用空格也是一样的
<%
Dim thetext
thetext=request("class")
'//Chr(10) 是换行符 Chr(13)是回车
ReDim myarray(200,4) '依具体情况而定 不一定是200 建议更大
for DyszIII=1 to 200
myarray(DyszIII,0)="0" '该行无效
myarray(DyszIII,1)="" 'ID
myarray(DyszIII,2)="" 'Name
myarray(DyszIII,3)="" 'Gender
myarray(DyszIII,4)="" 'xxx
next
SuZuIII=1 '节点
thetextSplit=split(thetext,Chr(10)) 'Chr(10)不行就改Chr(13)试试
for spiii=0 to Ubound(thetextSplit)
if trim(thetextSplit(spiii))<>"" then
TheGuochengCanshu=trim(thetextSplit(spiii))
TheGuochengCanshuSplit=split(TheGuochengCanshu," ")
myarray(SuZuIII,0)="1" '该行有效
myarray(SuZuIII,1)=SuZuIII 'ID
myarray(SuZuIII,2)=TheGuochengCanshuSplit(0) 'Name
myarray(SuZuIII,3)=TheGuochengCanshuSplit(1) 'Gender
myarray(SuZuIII,4)=TheGuochengCanshuSplit(2) 'xxx
SuZuIII=SuZuIII+1
end if
next
set rs=ServerCreateObject("ADODBRecordset")
sql="select top 1 from 表名"
rsopen sql,conn,3,3
for DyszIII=1 to SuZuIII-1
if myarray(DyszIII,0)="1" then
rsaddnew
rs("I")=myarray(DyszIII,1)
rs("A")=myarray(DyszIII,2)
rs("B")=myarray(DyszIII,3)
rs("C")=myarray(DyszIII,4)
rsupdate
next
next
rsclose
set sql=nothing
%>
//添加注册
private void button2_Click(object sender, EventArgs e)
{
if (textBox1TextLength != 0 && textBox2TextLength != 0)
{
SqlConnection sc = new SqlConnection("data source=;initial catalog=Cexercise;user id=sa;password=123;");
try
{
scOpen();
SqlCommand scd = new SqlCommand("select from userss where name='" + textBox1TextTrim() + "'", sc);
SqlDataReader sdr = scdExecuteReader();
if (!sdrHasRows)
{
sdrClose();
SqlCommand scon = new SqlCommand("insert into userss values('" + textBox1Text + "','" + textBox2Text + "')", sc);
int res = sconExecuteNonQuery();
MessageBoxShow("注册成功," + textBox1Text + "欢迎你!");
}
else
{
MessageBoxShow("注册失败,已经有该用户,请重新输入注册信息^ _^");
textBox1Text = "";
textBox2Text = "";
textBox1Focus();
}
}
catch (Exception ex)
{
MessageBoxShow(" *** 作失败,请检查网络连接是否正常!");
}
finally
{
if (scState == ConnectionStateOpen)
scClose();
}
}
}
你在VS中看的数据库是项目中的数据库,你编译时用到的的数据库是debug下的数据库文件,查看你项目中数据库的“复制到输出目录”属性,肯定是始终复制,意思就是每次拟推迟编译的时候会把你项目中的数据库覆盖你debug下的数据库,所以你每次编译后虽然在debug下的数据库成功更改数据了,但是之后就会被外面的数据库覆盖。
解决办法:
在程序的main函数中添加如下代码:
string dataDir = AppDomainCurrentDomainBaseDirectory;
if(dataDirEndsWith(@"\bin\Release\")||dataDirEndsWith(@"\bin\Debug\"))
{
dataDir = SystemIODirectoryGetParent(dataDir)ParentParentFullName;
AppDomainCurrentDomainSetData("DataDirectory", dataDir);
}
放在主窗口代码运行之前,就一劳永逸的解决了这个问题啊
以上就是关于ASP批量写入数据库问题全部的内容,包括:ASP批量写入数据库问题、C#无法写入数据库数据、C# VS2010中linq可以读入数据库,却无法写入数据库等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)