|
|
|
ใครพอทราบวิธี insert ลงฐานข้อมูลแล้วให้โชว์ใน datagridview |
|
|
|
|
|
|
|
ขอบคุณคร๊าบ เว็บนี้ดีจริงๆ มีประโยชน์ต่อเยาวชนที่ต้องการเรียนรู้
|
|
|
|
|
Date :
2011-04-04 12:59:05 |
By :
cazyboy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พี่คร๊าบผมลองทำแล้ว มันไม่บันทึกลงฐานข้อมูลไม่มี error อะไรขึ้นด้วยคร๊าบ ไม่รู้ว่าเขียนโค้ดผิดตรงไหนหรือเปล่า
ช่วยดูให้หน่อย เพิ่งเริ่มเขียนเว็บครับ
Code (VB.NET)
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="addformdetial.aspx.vb" Inherits="addformdetial" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<script runat="server">
Sub Wizard1_click(ByVal sender As Object, ByVal e As EventArgs)
Dim objConn As New OleDbConnection
Dim objCmd As New OleDbCommand
Dim strConnString, strSQL As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("qadatabase.mdb") & ";Jet OLEDB:Database Password=;"
strSQL = "INSERT INTO comment (cm_id,title,cm_name,post_date,cm_pic) " & _
" VALUES " & _
" ('" & Me.txt1.Text & "','" & Me.txt2.Text & "','" & Me.txt3.Text & "', " & _
" '" & Me.FileUpload1.ToString & "','" & Me.txt4.Text & "')"
objConn.ConnectionString = strConnString
objConn.Open()
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Me.Wizard1.Visible = False
Try
objCmd.ExecuteNonQuery()
Me.lblstatus.Visible = "Record Inserted"
Me.lblstatus.Visible = True
Catch ex As Exception
Me.lblstatus.Visible = True
Me.lblstatus.Text = "Record can not insert Error (" & ex.Message & ")"
End Try
objConn.Close()
objConn = Nothing
End Sub
'*********** อีก code *****************
'Dim objConn As OleDbConnection
'Dim objCmd As OleDbCommand
' Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'Dim strConnString As String
' strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("D:/QA2/qadatabase.mdb") & ";"
'objConn = New OleDbConnection(strConnString)
' objConn.Open()
' BindData()
' End Sub
</script>
<head runat="server">
<title> Customer Claim </title>
<script type="text/javascript">
</script>
<style type="text/css" runat="server">
#Reset1
{
width: 60px;
}
#Submit1
{
width: 64px;
}
.style9
{
height: 12px;
width: 121px;
}
.style10
{
height: 12px;
width: 287px;
}
.style11
{
height: 32px;
width: 121px;
}
.style12
{
height: 32px;
width: 287px;
}
.style13
{
height: 10px;
width: 121px;
}
.style14
{
height: 10px;
width: 287px;
}
.style15
{
height: 6px;
width: 121px;
}
.style16
{
height: 6px;
width: 287px;
}
.style17
{
height: 11px;
width: 121px;
}
.style18
{
height: 11px;
width: 287px;
}
</style>
<script type="text/javascript">
function setNextFocus(cm_id){
if (event.keyCode == 6){
var obj=document.getElementById(cm_id);
if (obj){
obj.focus();
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server" >
<div style="width: 769px; height: 430px;">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Image ID="Image1" runat="server" Height="100px" ImageAlign="AbsMiddle"
ImageUrl="~/logo.jpg" Width="120px" />
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large"
Text="Product Customer Claim"></asp:Label>
<hr style="border: thin hidden #000000; height: 8px; background-color: #C0C0C0;" />
<asp:Wizard ID="Wizard1" runat="server" BackColor="#EFF3FB"
BorderColor="#B5C7DE" BorderWidth="1px" Font-Names="Verdana" Font-Size="Small"
Height="217px" Width="759px">
<StepStyle Font-Size="0.8em" ForeColor="#333333" />
<WizardSteps>
<asp:WizardStep runat="server" title="ข้อมูลทั่วไป">
<table style="width: 80%; height: 165px;" border="1" >
<tr>
<td class="style13">
รหัสรายการ :</td>
<td class="style14">
<asp:TextBox ID="txt1" runat="server" MaxLength="6"
EnableViewState="False" value="" onkeydown="setNextFocus('txt1');" > </asp:TextBox>
</td>
</tr>
<tr>
<td class="style15">
ชื่อเรื่อง :</td>
<td class="style16">
<asp:TextBox ID="txt2" type="txt2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style17">
ผู้โพสต์ :</td>
<td class="style18">
<asp:TextBox ID="txt3" type="txt3" runat="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td class="style9">
ไฟล์เอกสาร:</td>
<td class="style10">
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
<tr>
<td class="style11">
วันที่:</td>
<td class="style12">
<asp:TextBox ID="txt4" type="txt4" runat="server" ></asp:TextBox>
</td>
</tr>
</table>
</asp:WizardStep>
</WizardSteps>
<SideBarButtonStyle BackColor="#507CD1" Font-Names="Verdana"
ForeColor="White" />
<NavigationButtonStyle BackColor="White" BorderColor="#507CD1"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em"
ForeColor="#284E98" />
<SideBarStyle BackColor="#507CD1" Font-Size="0.9em" VerticalAlign="Top" />
<HeaderStyle BackColor="#284E98" BorderColor="#EFF3FB" BorderStyle="Solid"
BorderWidth="2px" Font-Bold="True" Font-Size="0.9em" ForeColor="White"
HorizontalAlign="Center" />
</asp:Wizard>
<br />
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/detial.aspx">BACK HOME</asp:LinkButton>
<br />
<br />
<asp:Label ID="lblstatus" runat="server" Visible="false"></asp:Label>
</div>
</form>
</body>
</html>
|
|
|
|
|
Date :
2011-04-04 15:42:53 |
By :
cazyboy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|