467,859 Members | 1,375 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,859 developers. It's quick & easy.

can't insert data to ms access

dear all,
please help me that my script cannot insert data to ms acces.

<%@ Page Language="vb" ContentType="text/html"%>
<%@ Import NameSpace = "System.Data" %>
<%@ Import NameSpace = "System.Data.OleDb" %>

<script runat="server">

Sub Insert_Btn (s As Object, e As EventArgs)
Dim Conn As OleDbConnection
Dim ConnCommand As OleDbCommand
Dim ConnString, InsertString As String
Dim batas_peminjaman As Integer
Dim InputNama_depan, InputNama_tengah, InputNama_belakang, InputNama_total As String

ConnString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=D:\Inetpub\wwwroot\Prak\perpustakaan.mdb"

Conn = New OleDbConnection (ConnString)
Conn.Open()

InputNama_depan = (txtnamadepan.Text)
InputNama_tengah = (txtnamatengah.Text)
InputNama_belakang = (txtnamabelakang.Text)
InputNama_total = ((InputNama_depan) + (InputNama_tengah) + (InputNama_belakang))

select case DropDownJenis.SelectedItem.Text
case "Dosen": batas_peminjaman = 30
case "MHS_IT": batas_peminjaman = 14
case "Non_IT": batas_peminjaman = 7
case else : batas_peminjaman = 5
end select

InsertString = " INSERT INTO pinjam (no_anggota, nama_anggota, alamat_anggota, email_anggota, fakjur, jenis_anggota, batas_peminjaman) VALUES ('" & txtno.Text & "', '" & InputNama_Total & "', '" & txtALAMAT.Text & "', '" & txtemail.Text & "', " & DropDownFakjur.SelectedItem.Text & ", '" & DropDownJenis.SelectedItem.Text & "', '" & batas_peminjaman & "')"

ConnCommand = New OleDbCommand (InsertString,Conn)

Conn.Close()
End Sub

</script>

<html>
<head>
<title>Insert Data </title>
<style type="text/css">
<!--
.style1 {
font-family: "Comic Sans MS";
font-weight: bold;
}
-->
</style>
</head>
<body>
<form runat="server">
<table width="100%" height="222" border="0" class="style1">
<tr>
<td width="164" height="26">No Anggota</td>
<td width="86"><div align="center"><strong>:</strong></div></td>
<td width="711">
<asp:TextBox ID="txtno" MaxLength="7" CssClass="style1" runat="server"/>
<asp:RequiredFieldValidator ID="Validatorno" ControlToValidate="txtno" ErrorMessage="No Anggota harus di ISI" Display="Static" runat="server"/>
<asp:RegularExpressionValidator ID="Regularno" ControlToValidate="txtno" ValidationExpression="\d{7}" ErrorMessage="Nomer anggota harus tujuh DIGIT" Display="Static" runat="server"/>
</td>
</tr>
<tr>
<td height="26">Nama Depan </td>
<td><div align="center"><strong>:</strong></div></td>
<td>
<asp:TextBox ID="txtnamadepan" CssClass="style1" runat="server"/>
<asp:RequiredFieldValidator ID="Validatornamadepan" ControlToValidate="txtnamadepan" ErrorMessage="NAMA DEPAN harus di ISI" Display="Static" runat="server"/>
</td>
</tr>
<tr>
<td height="26">Nama tengah </td>
<td><div align="center"><strong>:</strong></div></td>
<td>
<asp:TextBox ID="txtnamatengah" CssClass="style1" runat="server"/>
</td>
</tr>
<tr>
<td height="26">Nama Belakang </td>
<td><div align="center"><strong>:</strong></div></td>
<td>
<asp:TextBox ID="txtnamabelakang" CssClass="style1" runat="server"/>
</td>
</tr>
<tr>
<td height="26">Alamat Anggota </td>
<td><div align="center"><strong>:</strong></div></td>
<td>
<asp:TextBox ID="txtalamat" CssClass="style1" runat="server"/>
<asp:RequiredFieldValidator ID="Validatoralamat" ControlToValidate="txtalamat" ErrorMessage="ALAMAT harus di ISI" Display="Static" runat="server"/>
</td>
</tr>
<tr>
<td height="26">Email Anggota </td>
<td><div align="center"><strong>:</strong></div></td>
<td><asp:TextBox ID="txtemail" CssClass="style1" runat="server"/></td>
</tr>

<tr>
<td height="24">Fakjur</td>
<td><div align="center"><strong>:</strong></div></td>
<td>
<asp:DropDownList ID="DropDownFakjur" CssClass="style1" runat="server">
<asp:ListItem Value="sastra_inggris">FS-S1 sastra Inggris</asp:ListItem>
<asp:ListItem Value="sastra_Jepang">FS-S1 sastra Jepang</asp:ListItem>
<asp:ListItem Value="D3_sastra_inggris">FS-D3 sastra Inggris</asp:ListItem>
<asp:ListItem Value="d3_sastra_mandarin">FS-D3 sastra mandarin</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td height="24">Golongan</td>
<td><div align="center"><strong>:</strong></div></td>
<td>
<asp:DropDownList ID="DropDownJenis" CssClass="style1" runat="server">
<asp:ListItem Value="dosen">Dosen</asp:ListItem>
<asp:ListItem Value="it">Mahasiswa IT</asp:ListItem>
<asp:ListItem Value="non_it">Mahasiswa Non IT</asp:ListItem>
<asp:ListItem Value="luar">Mahasiswa Luar</asp:ListItem>
</asp:DropDownList>
</td>
</tr>

<tr>
<td height="52" colspan="3">
<asp:Button Text="Insert-Data" OnClick="Insert_Btn" runat="server"/>
<asp:Label ID="txtResult" runat="server" ForeColor="#009999"/></td>
</tr>
</table>
<hr color="#009999">
<hr color="#009999">
</form>
</body>
</html>
Apr 4 '07 #1
  • viewed: 1611
Share:
1 Reply
dip_developer
Expert 512MB
dear all,
please help me that my script cannot insert data to ms acces.

<%@ Page Language="vb" ContentType="text/html"%>
<%@ Import NameSpace = "System.Data" %>
<%@ Import NameSpace = "System.Data.OleDb" %>

<script runat="server">

Sub Insert_Btn (s As Object, e As EventArgs)
Dim Conn As OleDbConnection
Dim ConnCommand As OleDbCommand
Dim ConnString, InsertString As String
Dim batas_peminjaman As Integer
Dim InputNama_depan, InputNama_tengah, InputNama_belakang, InputNama_total As String

ConnString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=D:\Inetpub\wwwroot\Prak\perpustakaan.mdb"

Conn = New OleDbConnection (ConnString)
Conn.Open()

InputNama_depan = (txtnamadepan.Text)
InputNama_tengah = (txtnamatengah.Text)
InputNama_belakang = (txtnamabelakang.Text)
InputNama_total = ((InputNama_depan) + (InputNama_tengah) + (InputNama_belakang))

select case DropDownJenis.SelectedItem.Text
case "Dosen": batas_peminjaman = 30
case "MHS_IT": batas_peminjaman = 14
case "Non_IT": batas_peminjaman = 7
case else : batas_peminjaman = 5
end select

InsertString = " INSERT INTO pinjam (no_anggota, nama_anggota, alamat_anggota, email_anggota, fakjur, jenis_anggota, batas_peminjaman) VALUES ('" & txtno.Text & "', '" & InputNama_Total & "', '" & txtALAMAT.Text & "', '" & txtemail.Text & "', " & DropDownFakjur.SelectedItem.Text & ", '" & DropDownJenis.SelectedItem.Text & "', '" & batas_peminjaman & "')"

ConnCommand = New OleDbCommand (InsertString,Conn)

Conn.Close()
End Sub

</script>

<html>
<head>
<title>Insert Data </title>
<style type="text/css">
<!--
.style1 {
font-family: "Comic Sans MS";
font-weight: bold;
}
-->
</style>
</head>
<body>
<form runat="server">
<table width="100%" height="222" border="0" class="style1">
<tr>
<td width="164" height="26">No Anggota</td>
<td width="86"><div align="center"><strong>:</strong></div></td>
<td width="711">
<asp:TextBox ID="txtno" MaxLength="7" CssClass="style1" runat="server"/>
<asp:RequiredFieldValidator ID="Validatorno" ControlToValidate="txtno" ErrorMessage="No Anggota harus di ISI" Display="Static" runat="server"/>
<asp:RegularExpressionValidator ID="Regularno" ControlToValidate="txtno" ValidationExpression="\d{7}" ErrorMessage="Nomer anggota harus tujuh DIGIT" Display="Static" runat="server"/>
</td>
</tr>
<tr>
<td height="26">Nama Depan </td>
<td><div align="center"><strong>:</strong></div></td>
<td>
<asp:TextBox ID="txtnamadepan" CssClass="style1" runat="server"/>
<asp:RequiredFieldValidator ID="Validatornamadepan" ControlToValidate="txtnamadepan" ErrorMessage="NAMA DEPAN harus di ISI" Display="Static" runat="server"/>
</td>
</tr>
<tr>
<td height="26">Nama tengah </td>
<td><div align="center"><strong>:</strong></div></td>
<td>
<asp:TextBox ID="txtnamatengah" CssClass="style1" runat="server"/>
</td>
</tr>
<tr>
<td height="26">Nama Belakang </td>
<td><div align="center"><strong>:</strong></div></td>
<td>
<asp:TextBox ID="txtnamabelakang" CssClass="style1" runat="server"/>
</td>
</tr>
<tr>
<td height="26">Alamat Anggota </td>
<td><div align="center"><strong>:</strong></div></td>
<td>
<asp:TextBox ID="txtalamat" CssClass="style1" runat="server"/>
<asp:RequiredFieldValidator ID="Validatoralamat" ControlToValidate="txtalamat" ErrorMessage="ALAMAT harus di ISI" Display="Static" runat="server"/>
</td>
</tr>
<tr>
<td height="26">Email Anggota </td>
<td><div align="center"><strong>:</strong></div></td>
<td><asp:TextBox ID="txtemail" CssClass="style1" runat="server"/></td>
</tr>

<tr>
<td height="24">Fakjur</td>
<td><div align="center"><strong>:</strong></div></td>
<td>
<asp:DropDownList ID="DropDownFakjur" CssClass="style1" runat="server">
<asp:ListItem Value="sastra_inggris">FS-S1 sastra Inggris</asp:ListItem>
<asp:ListItem Value="sastra_Jepang">FS-S1 sastra Jepang</asp:ListItem>
<asp:ListItem Value="D3_sastra_inggris">FS-D3 sastra Inggris</asp:ListItem>
<asp:ListItem Value="d3_sastra_mandarin">FS-D3 sastra mandarin</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td height="24">Golongan</td>
<td><div align="center"><strong>:</strong></div></td>
<td>
<asp:DropDownList ID="DropDownJenis" CssClass="style1" runat="server">
<asp:ListItem Value="dosen">Dosen</asp:ListItem>
<asp:ListItem Value="it">Mahasiswa IT</asp:ListItem>
<asp:ListItem Value="non_it">Mahasiswa Non IT</asp:ListItem>
<asp:ListItem Value="luar">Mahasiswa Luar</asp:ListItem>
</asp:DropDownList>
</td>
</tr>

<tr>
<td height="52" colspan="3">
<asp:Button Text="Insert-Data" OnClick="Insert_Btn" runat="server"/>
<asp:Label ID="txtResult" runat="server" ForeColor="#009999"/></td>
</tr>
</table>
<hr color="#009999">
<hr color="#009999">
</form>
</body>
</html>



i think its a silly mistake ...
Where is the code for execution of your command object.
Put ConnCommand .ExecuteNonQuery()
Apr 4 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Ervs Sevilla via SQLMonster.com | last post: by
1 post views Thread by Abareblue | last post: by
2 posts views Thread by Geoffrey KRETZ | last post: by
1 post views Thread by Jim | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.