查看: 1020|回复: 5
|
ASP.Net 菜鸟 。。。 :(
[复制链接]
|
|
各位网页高手,我是一个菜鸟,想刚开始学写简单的 program by using ASP.net
我要写 -〉一个简单的 text box (input data) -> 然后 store in microsoft sql server db
-> 然后 拿回 data display out ....就将简单。。?
请问有谁可以帮我吗? 谁有空的可以把那个 coding 写出来吗? 在此先谢了。
或则各位高手可以告诉我要从何开始,要用到什么coding 将。谢谢帮忙我这位菜鸟了。 |
|
|
|
|
|
|
|
发表于 11-10-2007 04:45 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 11-10-2007 05:15 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 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
<asp abel 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 编辑 ] |
|
|
|
|
|
|
| |
本周最热论坛帖子
|