PDA

View Full Version : ارتباط dataset با gridview



amir_T_2008
چهارشنبه 10 دی 1393, 11:59 صبح
سلام دوستان من واقعا چند هفته هستش درگیر یه مشکلم ممنون میشم من و از شر این مشکل خلاص کنید

من دارم سبد خرید طراحی میکنم و میخوام وقتی کاربر کالاش انتخاب کرد و به قسمت سبد رفت اونجا به وسیله گریدویو کالایی که انتخاب کرده نمایش بده و بعد با زدن دکمه تایید تو دیتابیس ثبت بشه حالا من میخوام با dataset انتقال بین گرید با دیتابیس انجام بده اما قبلش از دیتاست استفاده نمیکنم حالا با کد زیر مشکل دارم




if (!IsPostBack)
{

// Declare the query string.
String queryString =
"Select [id],[ProductID],[date],[Name],[price],[fIsChecked],[fFishNumber],[fBankName] From [tSells]";
// Run the query and bind the resulting DataSet
// to the GridView control.

DataSet ds = GetData(queryString);
if (ds.Tables.Count > 0)
{

GridView1.DataSource = ds; ;
GridView1.DataBind();

}
else
{
Message.Text = "Unable to connect to the database.";
}

}

}

DataSet GetData(String queryString)
{

// Retrieve the connection string stored in the Web.config file.
String connectionString = ConfigurationManager.ConnectionStrings["dbarchitect"].ConnectionString;

DataSet ds = new DataSet();

try
{
// Connect to the database and run the query.
SqlConnection connection = new SqlConnection(connectionString);
SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection);

// Fill the DataSet.
adapter.Fill(ds);

}
catch (Exception ex)
{

// The connection failed. Display an error message.
Message.Text = "Unable to connect to the database.";

}

return ds;

}



حالا تو کد بالا من باید ds از Profile.SCart.Items پر کنم وگرنه عکس زیر ظاهر میشه




GridView1.DataSource = Profile.SCart.Items;
DataBind();

127065

من نمیدونم چطوری باید دیتاستم(ds) از Profile.SCart.Items پر کنم که این مشکل پیش نیاد.

ممنون میشم کمک کنید

amir_T_2008
چهارشنبه 10 دی 1393, 19:09 عصر
يعني هيچ كس نمي تونه اين مشكل حل كنه؟؟؟؟؟؟؟؟؟