PDA

View Full Version : Reference to a non-shared member requires an object reference



mis toity
یک شنبه 23 تیر 1387, 13:44 عصر
سلام
لطفا بررسی کنید دلیل این خطا چیه؟
" Reference to a non-shared member requires an object reference "
کد برنامه:


<%@ Import Namespace="system.data.sqlclient" %>
<%@ Import Namespace="system.data" %>
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="testproject._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.Visible = False
TextBox2.Visible = False
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
Label4.Visible = False
Button2.Visible = False
Dim scon As SqlConnection
scon = New SqlConnection("Data Source=TSIT-L1\SQLEXPRESS;Initial Catalog=personnel;Integrated Security=True")
Dim scom As SqlCommand
scon.Open()
scom = New SqlCommand(" select * from personnel1", scon)
GridView1.DataSource = scom.ExecuteReader
GridView1.DataBind()
scon.Close()
End Sub



Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
TextBox1.Visible = True
TextBox2.Visible = True
Label1.Visible = True
Label2.Visible = True
Label3.Visible = True
Button2.Visible = True
End Sub

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
Dim scon As SqlConnection
scon = New SqlConnection("Data Source=TSIT-L1\SQLEXPRESS;Initial Catalog=personnel;Integrated Security=True")
Dim scom As SqlCommand
scon.Open()
scom = New SqlCommand(" select * from personnel1", scon)
GridView1.DataSource = scom.ExecuteReader
GridView1.DataBind()
scon.Close()


End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
Dim scon As SqlConnection
scon = New SqlConnection("Data Source=TSIT-L1\SQLEXPRESS;Initial Catalog=personnel;Integrated Security=True")
Dim scom As SqlCommand
scon.Open()
scom = New SqlCommand(" insert into personnel1 (name,family) values ('" & TextBox1.Text & "','" & TextBox2.Text & "')", scon)
scom.ExecuteReader()
scon.Close()
TextBox1.Text = ""
TextBox2.Text = ""
Label4.Visible = True

End Sub
End Class
</script>


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">

<br />
&nbsp;&nbsp;
<asp:Label ID="Label5" runat="server" EnableViewState="False"
Text="personnel list :"></asp:Label>
&nbsp;&nbsp;<br />
<br />
<asp:Button ID="Button3" runat="server" EnableViewState="False" Height="32px"
style="margin-bottom: 0px" Text="Updata" Width="66px" />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" Height="32px"
style="margin-bottom: 0px" Text="insert" Width="66px" />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
<asp:GridView ID="GridView1" runat="server" BackColor="#CCCCCC"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CaptionAlign="Top"
CellPadding="4" CellSpacing="2" EnableViewState="False" ForeColor="Black"
HorizontalAlign="Left">
<FooterStyle BackColor="#CCCCCC" />
<RowStyle BackColor="White" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<br />
&nbsp;<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
&nbsp;&nbsp;&nbsp;
<br />
<br />
&nbsp;&nbsp;
<asp:Label ID="Label4" runat="server" Text="SUCCESSFULLY COMPLETE"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br />
&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server"
Text="please insert your name &amp; family:"></asp:Label>
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label2" runat="server" Text="name"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server" EnableViewState="False" Height="22px"></asp:TextBox>
<br />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label3" runat="server" Text="family"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox2" runat="server" EnableViewState="False"
style="margin-top: 9px"></asp:TextBox>
<br />
<br />
&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
<asp:Button ID="Button2" runat="server" Height="32px"
style="margin-bottom: 0px" Text="ok" Width="66px" />
<br />
<br />
</form>
</body>
</html>


با تشکر

mehranFX
یک شنبه 23 تیر 1387, 14:05 عصر
به طور کلی این خطا زمانی مشاهده میشه که شما بخواهید به عناصر یک آبجکت دسترسی پیدا کنید بدون اینکه اون آبجکت را با کلمه کلیدی New مقدار دهی اولیه کرده باشید.
موفق باشید

mis toity
یک شنبه 23 تیر 1387, 14:29 عصر
این خطا روی همه اشیایی که داخل فرم گذاشتم از جمله textbox,lableو... نشون داده می شه
می شه لطفا بیشتر راهنمایی کنید

mehranFX
یک شنبه 23 تیر 1387, 14:38 عصر
سورس کد قسمت مشکل دار را آپلود کنید.

mis toity
دوشنبه 24 تیر 1387, 13:44 عصر
سلام
فایل اجرایی رو در قسمت ضمیمه گذاشتم