佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1020|回复: 5

ASP.Net 菜鸟 。。。 :(

[复制链接]
发表于 19-9-2007 07:18 PM | 显示全部楼层 |阅读模式
各位网页高手,我是一个菜鸟,想刚开始学写简单的 program by using ASP.net

我要写 -〉一个简单的 text box (input data) -> 然后 store in microsoft sql server db
-> 然后 拿回 data display out ....就将简单。。? 

请问有谁可以帮我吗? 谁有空的可以把那个 coding 写出来吗? 在此先谢了。

或则各位高手可以告诉我要从何开始,要用到什么coding 将。谢谢帮忙我这位菜鸟了。
回复

使用道具 举报


ADVERTISEMENT

发表于 11-10-2007 04:45 PM | 显示全部楼层

回复 #1 mousseyang 的帖子

我也想学。。。你们可以教一教吗?谢谢。。
回复

使用道具 举报

发表于 11-10-2007 05:15 PM | 显示全部楼层
原帖由 mousseyang 于 19-9-2007 07:18 PM 发表
各位网页高手,我是一个菜鸟,想刚开始学写简单的 program by using ASP.net

我要写 -〉一个简单的 text box (input data) -> 然后 store in microsoft sql server db
-> 然后 拿回 data display out .... ...

首先你要在Sql server create table..

asp.net code behind. declare sqlConnection 和 SqlCommand
然后用Tsql 来写command..

tsql 的command 可以在google 找..
找开头 [size=-1]doc.ddart.net/mssql的比较清楚..
回复

使用道具 举报

发表于 11-10-2007 09:54 PM | 显示全部楼层
原帖由 mousseyang 于 19-9-2007 07:18 PM 发表
各位网页高手,我是一个菜鸟,想刚开始学写简单的 program by using ASP.net

我要写 -〉一个简单的 text box (input data) -> 然后 store in microsoft sql server db
-> 然后 拿回 data display out .... ...

Add one new Class in your asp,net project under the "App_Code" folder and name it as clsSQL
copy the following coding to the which u have created.

Part 1
'Class Coding Start
    Imports System.Data
    Imports System.Data.SqlClient
Public Class clsMSSQL
    Sub ExecuteSQLStatement(ByVal ssql As String)
         Dim myConn As New SqlConnection( "server=yourservername; database=yourdatabasename; uid=yourSQLLoginID; pwd=yourSQLLoginPassword")
        Dim MyDataAdapter As New SqlDataAdapter
        Dim MyCommand As New SqlCommand
        Dim MyDS As New DataSet

        Try
            MyCommand.Connection = myConn
            myConn.Open()

            MyCommand.CommandText = ssql
            MyCommand.ExecuteNonQuery()
        Catch ex As Exception
                'Put your error handling here
        Finally
            If Not myConn.State = ConnectionState.Closed Then
                myConn.Close()
            End If
        End Try
    End Function
End Class
'Class Coding End

[ 本帖最后由 天下人管天下事 于 11-10-2007 10:09 PM 编辑 ]
回复

使用道具 举报

发表于 11-10-2007 09:59 PM | 显示全部楼层
Part 2

In your web designer (the one with extension .aspx), copy and paste this few lines of coding

<aspabel id="lblName" runat="server" Text="Name" ></asp:/Label>
<asp:TextBox id="txtName" runat="server" ></asp:TextBox>
<br />
<asp:Button id="btnSubmit" runat="server" Text="Submit" ></asp:Button>

回复

使用道具 举报

发表于 11-10-2007 10:08 PM | 显示全部楼层
Part 3
    In your MS SQL database, create a table name as [TableName]

    Create Table TableName([Name] nvarchar(100))

Part 4
    In your code file , the one with extension .aspx.vb
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
         If txtName.Text.ToString.Trim()="" Then
                Response.Write("Name Is A Required Field!")
                txtName.Focus()
         Else
             Dim mySQL As New clsSQL
              mySQL.ExecuteSQLStatement("Insert Into TableName([Name]) Values('" & txtName.Text.ToString() & "')"
               txtName.Clear()
                Response.Write("Record inserted to database!")
         End If
    End Sub

[ 本帖最后由 天下人管天下事 于 11-10-2007 10:11 PM 编辑 ]
回复

使用道具 举报

Follow Us
您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 13-10-2025 02:09 AM , Processed in 0.143847 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表