命名空间/参考 [英] Namespace/References

查看:56
本文介绍了命名空间/参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

我有一个网络应用程序.我在项目中添加了一个新项目到用于访问DAL的数据的解决方案中,该项目具有我已引用我的网站的类SQLHelper.cs.

现在在我的SQLHelper.cs类中,我正在编写此文件-

SqlConnection conn = GetConnection();
SqlCommand cmd =新的SqlCommand();
cmd.CommandText =插入tblProducts(ProductName,QtyAvailable,Rate)VALUES(@ ProductName,@ QtyAvailable,@ Rate)";
cmd.Parameters.Add("@ ProductName",SqlDbType.VarChar).Value =((TextBox)GridView1.Rows [0] .Cells [2] .Controls [0]).Text;
cmd.Parameters.Add("@ QtyAvailable",SqlDbType.SmallInt).Value =((TextBox)GridView1.Rows [0] .Cells [3] .Controls [0]).Text;
cmd.Parameters.Add("@ Rate",SqlDbType.Int).Value =((TextBox)GridView1.Rows [0] .Cells [4] .Controls [0]).Text;

cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();


并且显示错误名称GridView1在当前上下文中不存在.我添加了这些引用SQLHelper.cs类-

Hey there,

I have a web app. project in which i have added a new project to the solution for data accessing DAL it has a class SQLHelper.cs that i has referenced to my website.

Now in my SQLHelper.cs class, I Am writing this--

SqlConnection conn = GetConnection();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO tblProducts(ProductName,QtyAvailable,Rate) VALUES(@ProductName,@QtyAvailable,@Rate)";
cmd.Parameters.Add("@ProductName", SqlDbType.VarChar).Value = ((TextBox)GridView1.Rows[0].Cells[2].Controls[0]).Text;
cmd.Parameters.Add("@QtyAvailable", SqlDbType.SmallInt).Value = ((TextBox)GridView1.Rows[0].Cells[3].Controls[0]).Text;
cmd.Parameters.Add("@Rate", SqlDbType.Int).Value = ((TextBox)GridView1.Rows[0].Cells[4].Controls[0]).Text;

cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();


And it is showing error the name GridView1 does not exist in the current context.I have added these refrences SQLHelper.cs class--

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts


;

还有什么失踪的家伙?....
谁能帮忙.plz

谢谢
授予


;

whats missing guys?....
can anyone help.plz

Thanks
Amit

推荐答案

通过方法参数将从网格中获取的值传递给SQLHelper.cs类中的方法,例如: />
Pass the values obtained from the grid to the method in your SQLHelper.cs class via method parameters, perhaps like:

public void InsertData(string productName, int qtyAvailable, int rate)<br />
{<br />
    ... rest of code<br />
}<br />


GridView1是GridView的实例,它在您的窗体上,而不在SQLHelper类中.如果要在此处使用它,则必须将其传递给类(通过函数或构造函数).这与对名称空间的引用无关.
GridView1 is an instance of a GridView and it is on your form, not in your SQLHelper class. If you want to use it there, you must pass it to the class (via a function or constructor). This has nothing to do with references to namespaces.


您正在SQLHelper.cs类中使用GridView1.而不是一个单独的类.... so来重组代码...
you are using GridView1 in the SQLHelper.cs class..the GridView1 is only accessible to the page.aspx.cs class...rather than to a seperate class....so restructure your code...


这篇关于命名空间/参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆