There is no row at column 0 - asp.net

I'm having one grid and one link button on that grid which have rowcommand but whenever i click on that button it shows me error that there is no row at column 0.
i've debugged whole code so many time but always it's showing me that there is no column even if there is data in that specific column of dataset.
I'm new to asp.net as well as to sql so only knowing that how to put code but logic is not getting cleared please can anyone clear this query. your help is too much for me.
protected void grdManageBRProperty_RowCommand(object sender, GridViewCommandEventArgs e)
{
Session["prptIdBRP"] = e.CommandArgument.ToString();
string id = Session["prptIdBRP"].ToString();
ds = obj.sel("select tblPropertyMaster.PropertyId, tblPropertyTypeMaster.PropertyTypeName, tblSubPropertyTypeMaster.PropertySubTypeName, tblPropertyMaster.Floor, tblPropertyMaster.PlotArea, tblPropertyMaster.BuitUpArea, tblPropertyMaster.ExpectedAmount, tblCityMaster.CityName, tblLocationMaster.LocationName, tblBuilderMaster.BuilderName, tblPropertyMaster.Description, tblPropertyMaster.Remarks, tblPropertyMaster.Furniture AS Furntr, tblPropertyMaster.IsAdvertise, tblPropertyMaster.Status, tblPropertyMaster.OwnerName, tblPropertyMaster.Address, tblPropertyMaster.ContactNo, tblPropertyMaster.MobileNo, tblPropertyMaster.EmailId from tblPropertyMaster INNER JOIN tblPropertyTypeMaster ON tblPropertyMaster.PropertyTypeId=tblPropertyTypeMaster.PropertyTypeId INNER JOIN tblSubPropertyTypeMaster ON tblPropertyMaster.PropertySubTypeId=tblSubPropertyTypeMaster.PropertySubTypeId INNER JOIN tblCityMaster ON tblPropertyMaster.CityId=tblCityMaster.CityId INNER JOIN tblLocationMaster ON tblPropertyMaster.LocationId=tblLocationMaster.LocationId INNER JOIN tblBuilderMaster ON tblPropertyMaster.BuilderName=tblBuilderMaster.BuilderId where tblPropertyMaster.PropertyId= '" + id + "'");
string furn = ds.Tables[0].Rows[0]["Furntr"].ToString();
if (furn == "True")
{
rbBRPFetchFurnitureYesC.Checked = true;
}
if (furn == "False")
{
rbBRPFetchFurnitureNoC.Checked = true;
}
string stts = ds.Tables[0].Rows[0]["Status"].ToString();
if (stts == "True")
{
rbBRPFetchStatusSoldC.Checked = true;
}
if (stts == "False")
{
rbBRPFetchStatusNtSoldC.Checked = true;
}
string advrts = ds.Tables[0].Rows[0]["IsAdvertise"].ToString();
if (advrts == "True")
{
rbBRPFetchIsAdYesC.Checked = true;
}
if (advrts == "False")
{
rbBRPFetchIsAdNoC.Checked = true;
}
ddlBRPFetchTypOfPrptC.SelectedItem.Text = ds.Tables[0].Rows[0]["PropertyTypeName"].ToString();
ddlBRPFetchSbTypOfPrptC.SelectedItem.Text = ds.Tables[0].Rows[0]["PropertySubTypeName"].ToString();
txtBRPFetchFloorC.Text = ds.Tables[0].Rows[0]["Floor"].ToString();
txtBRPFetchPlotAreaC.Text = ds.Tables[0].Rows[0]["PlotArea"].ToString();
txtBRPFetchBiultUpAreaC.Text = ds.Tables[0].Rows[0]["BuitUpArea"].ToString();
txtBRPFetchAmountC.Text = ds.Tables[0].Rows[0]["ExpectedAmount"].ToString();
ddlBRPFetchCityC.SelectedItem.Text = ds.Tables[0].Rows[0]["CityName"].ToString();
ddlBRPFetchLocationC.SelectedItem.Text = ds.Tables[0].Rows[0]["LocationName"].ToString();
ddlBRPFetchBuilderNameC.SelectedItem.Text = ds.Tables[0].Rows[0]["BuilderName"].ToString();
txtBRPFetchDescC.Text = ds.Tables[0].Rows[0]["Description"].ToString();
txtBRPFetchRemrksC.Text = ds.Tables[0].Rows[0]["Remarks"].ToString();
txtBRPFetchOwnerNameC.Text = ds.Tables[0].Rows[0]["OwnerName"].ToString();
txtBRPFetchAddressC.Text = ds.Tables[0].Rows[0]["Address"].ToString();
txtBRPFetchConNumberC.Text = ds.Tables[0].Rows[0]["ContactNo"].ToString();
txtBRPFetchMobNumberC.Text = ds.Tables[0].Rows[0]["MobileNo"].ToString();
txtBRPFetchEmailC.Text = ds.Tables[0].Rows[0]["EmailId"].ToString();
pnlBRPUpdateBySessionCriteria.Visible = true;
pnlSearchBRPByDate.Visible = false;
pnlBRPManageGrid.Visible = false;
}

As a precautionary step always first check Rows are present and then only extract values from rows.
if(ds.Tables[0].Rows.Count > 0)
{
// Your code
}

Related

How to populate data related to an item from the location which is same for all items in Xamarin.forms

I am developing an xamarin.forms app ,I have various fields like Item Name ,Item Number and location ,here Location of all the items are same ,by entering names or number of the items the values are generated automatically because name and number are unique but since the location number is common is for all the items I am not able to populate correct data related to a particular field ,I am using sqlite database in my project can anyone please suggest me on what basis can I generate related values ?
Here is the code
public async void OnSearch_Location(object o, EventArgs args)
{
if (location.Text == string.Empty || location.Text == null)
{
await Navigation.PushAsync(new ListValuePage("Location", filePath,
pos, list));
}
else
{
for (int p = 0; p < list.Count; p++)
{
if (list.ElementAt(p).Aisle + "." + list.ElementAt(p).Bin +
"." + list.ElementAt(p).Level == location.Text)
{
line.Text =
Convert.ToString(list.ElementAt(p).Line_Number);
location.Text = list.ElementAt(p).Aisle + "." +
list.ElementAt(p).Bin + "." + list.ElementAt(p).Level;
item.Text = list.ElementAt(p).Item_Number;
name.Text = list.ElementAt(p).Name;
if (list.ElementAt(p).Order_Qty == 0)
{
order_uom.Text = "";
}
else
{
order_qty.Text =
Convert.ToString(list.ElementAt(p).Order_Qty);
}
order_uom.Text = list.ElementAt(p).Order_UOM;
if (list.ElementAt(p).Consumption_UOM == string.Empty ||
list.ElementAt(p).Consumption_UOM == null)
{
consume_lbl.IsVisible = false;
consume_qty.IsVisible = false;
consume_uom.IsVisible = false;
}
else
{
consume_lbl.IsVisible = true;
consume_qty.IsVisible = true;
consume_uom.IsVisible = true;
if (list.ElementAt(p).Consumption_Qty == 0)
{
consume_qty.Text = "";
}
else
{
consume_qty.Text =
Convert.ToString(list.ElementAt(p).Consumption_Qty);
}
consume_uom.Text = list.ElementAt(p).Consumption_UOM;
}
}
}
}
}

How to perform Rollback in asp.net when using Stored Procedure

I want to insert data into 12 different tables on a single click of a button. For this I am using single stored procedure. But my problem is when I am doing this and if there is any exception occurs my data is getting inserted partially i.e values is getting inserted in some tables and some remains empty and due to this problem occurs since all are related to one another. So wanted to know is there any way to perform Rollback so that if any exception occurs entire query is rolled back and data is not inserted in any of the table.
This is the code I am currently using for inserting values.
public int Sp_InsertUpdateDelete(string s, SqlParameter[] spa)
{
SqlConnection sc = new SqlConnection(cs);
sc.Open();
SqlCommand scm = new SqlCommand(s, sc);
scm.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter sql in spa)
{
scm.Parameters.Add(sql);
}
int k = scm.ExecuteNonQuery();
sc.Close();
return k;
}
protected void btnHostingSubmit_Click(object sender, EventArgs e)
{
string select = "select * from tbl_Hosting where Customer_Id='" + ddlCustomerName.SelectedValue + "'";
DataSet s = gs.select(select);
if (s.Tables[0].Rows.Count > 0)
{
Response.Write("<script>alert('Customer Already Exist');</script>");
}
else
{
if (ddlHosting.SelectedValue == "Yes")
{
SqlParameter[] spa = new SqlParameter[29];
spa[0] = new SqlParameter("#Customer_Id", Convert.ToInt16(ddlCustomerName.SelectedValue));
spa[1] = new SqlParameter("#Type", 2);
//Hosting
if (txtHostingSDate.Text == "" || txtHostingSDate.Text == null)
{
spa[2] = new SqlParameter("#Hosting_start_date", null);
}
else
{
spa[2] = new SqlParameter("#Hosting_start_date", Convert.ToDateTime(txtHostingSDate.Text));
}
if (txtHosingEDate.Text == "" || txtHosingEDate.Text == null)
{
spa[3] = new SqlParameter("#Hosting_end_date", null);
}
else
{
spa[3] = new SqlParameter("#Hosting_end_date", Convert.ToDateTime(txtHosingEDate.Text));
}
spa[4] = new SqlParameter("#Hosting_provider", ddlHostingPro.SelectedItem.ToString());
spa[5] = new SqlParameter("#Hosting_type", ddlHostingType.SelectedItem.ToString());
spa[6] = new SqlParameter("#Hosting_server", ddlHostingServer.SelectedItem.ToString());
spa[7] = new SqlParameter("#Hosting_total_id", Convert.ToInt16(txtHostingId.Text));
spa[8] = new SqlParameter("#Hosting_mail_tracking", ddlHostingMailTracking.SelectedItem.ToString());
spa[9] = new SqlParameter("#Hosting_mail_tracking_users", Convert.ToInt16(txtHostingMtUser.Text));
spa[10] = new SqlParameter("#Hosting_dns", ddlHostingDns.SelectedItem.ToString());
spa[11] = new SqlParameter("#Hosting_mail", ddlHostingMail.SelectedItem.ToString());
spa[12] = new SqlParameter("#Hosting_web", ddlHostingWeb.SelectedItem.ToString());
spa[13] = new SqlParameter("#Hosting_manage_dns", ddlHostingMngDns.SelectedItem.ToString());
if (ddlHostingDns.SelectedValue == "No" && (ddlHostingMail.SelectedValue == "Yes" || ddlHostingWeb.SelectedValue == "Yes"))
{
spa[14] = new SqlParameter("#Hosting_ns1", txtNS1.Text);
spa[15] = new SqlParameter("#Hosting_ns2", txtNS2.Text);
}
else
{
spa[14] = new SqlParameter("#Hosting_ns1", ddlHostingNS1.SelectedItem.ToString());
spa[15] = new SqlParameter("#Hosting_ns2", ddlHostingNS2.SelectedItem.ToString());
}
spa[16] = new SqlParameter("#Hosting_rec_ip", txtHostingARecordIp.Text);
spa[17] = new SqlParameter("#Hosting_mx_rec1", txtMXRecord1.Text);
spa[18] = new SqlParameter("#Hosting_mx_rec2", txtMXRecord2.Text);
spa[19] = new SqlParameter("#Hosting_mx_ip1", txtHostingMxIp1.Text);
spa[20] = new SqlParameter("#Hosting_space", ddlHostingSpace.SelectedItem.ToString());
spa[21] = new SqlParameter("#Hosting_mx_ip2", txtHostingMxIp2.Text);
spa[22] = new SqlParameter("#Hosting_data_transfer", ddlhostingDataTrans.SelectedItem.ToString());
spa[23] = new SqlParameter("#Hosting_manage_dns_amt", txtHostingMangDnsAmt0.Text);
spa[24] = new SqlParameter("#Hosting_amt", txtHostingAmt0.Text);
spa[25] = new SqlParameter("#Hosting_c_ns1", txtHostingNS1.Text);
spa[26] = new SqlParameter("#Hosting_c_ns2", txtHostingNS2.Text);
spa[27] = new SqlParameter("#Hosting_c_ns3", txtHostingNS3.Text);
spa[28] = new SqlParameter("#Hosting_c_ns4", txtHostingNS4.Text);
int k = gs.Sp_InsertUpdateDelete("Sp_Hosting", spa);
if (k > 0)
{
Response.Write("<script>alert('Hosting Added Success');</script>");
}
Clear();
}
using(SqlConnection conn = new SqlConnection())
{
try
{
conn.Open();
SqlTransaction tran = conn.BeginTransaction("Transaction1");
Cmd = new SqlCommand(sQuery, Conn);
Cmd.Transaction = tran;
//Your Code
tran.Commit(); //both are successful
}
catch(Exception ex)
{
//if error occurred, reverse all actions. By this, your data consistent and correct
tran.Rollback();
}
}
https://msdn.microsoft.com/en-us/library/a90c30fy.aspx
You need to modify your Stored procedure and use Transactions for this feature.
Something like this:
DECLARE #TranName VARCHAR(20);
SELECT #TranName = 'MyTransaction';
BEGIN TRANSACTION #TranName;
USE AdventureWorks2012;
DELETE FROM AdventureWorks2012.HumanResources.JobCandidate
WHERE JobCandidateID = 13;
COMMIT TRANSACTION #TranName;
GO
MSDN Reference

How to count the no of records in gridview which have some particular data in a coloumn

How to count the no of records in Gridview which have some particular data in a column
name result
======== ======
krishna pass
sanjay pass
ajay fail
out put needed in grid view - above Gridview already present,according to that grid i have to make another grid to count results
result no
====== =====
pass 2
fail 1
in data row bound , i calculated
protected void GVKeywordReport_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow pr = ((DataRowView)e.Row.DataItem).Row;
int oldPos = Convert.ToInt32(pr["oldposition"]);
int newPos = Convert.ToInt32(pr["newposition"]);
GVKeywordReport.HeaderRow.Cells[3].Text = txtfrmdate.Text;
GVKeywordReport.HeaderRow.Cells[4].Text = txtEndDate.Text;
GVKeywordReport.HeaderRow.BackColor = ColorTranslator.FromHtml("#B3B300");
e.Row.Cells[0].BackColor = ColorTranslator.FromHtml("#B3B300");
e.Row.Cells[5].BackColor = ColorTranslator.FromHtml("#FFFFFF");
if (oldPos == newPos)
{
e.Row.BackColor = ColorTranslator.FromHtml("#FF950E");
e.Row.Cells[6].Text = "No Change";
nc= nc+1;
}
else if (oldPos > newPos)
{
e.Row.BackColor = ColorTranslator.FromHtml("#FFFFCC");
e.Row.Cells[6].Text = "Improved";
imprv= imprv+1;
}
else
{
e.Row.BackColor = ColorTranslator.FromHtml("#FF0000");
e.Row.Cells[6].Text = "Decreased";
decrs=decrs+1;
}
// e.Row.Cells[0].BackColor = ColorTranslator.FromHtml("#7DA647");
}
txt_TargetReached.Text = "0";
txtDecreased.Text =Convert.ToString(decrs);

How to add filters with customer data source of telerik reporting?

I set my report‘s data source in the backstage of the page that display the report.The code is below:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string acceptedStatus = QuoteStatusEnum.Accepted.ToString();
string rejectedStatus = QuoteStatusEnum.Rejected.ToString();
string canceledStatus = QuoteStatusEnum.Canceled.ToString();
IList<QuoteRequest> list = ServiceFactory.QuoteRequestService.QueryItems(p => (p.QuoteRequestStatus.QuoteRequestStatusName == acceptedStatus) ||
(p.QuoteRequestStatus.QuoteRequestStatusName == rejectedStatus) ||
(p.QuoteRequestStatus.QuoteRequestStatusName == canceledStatus)).OrderBy(p => p.CreatedBy).ToList();
var data = from d in list
select new
{
ClientName = d.Client.CompanyName,
Client = d.Client.ClientID,
CompanyName = d.Client.CompanyName,
QuoteNumber = d.QuoteNumber,
PropertyAddress = d.Property.PropertyAddressLine1 + (string.IsNullOrEmpty(d.Property.PropertyAddressLine2) ? "" : " ," + d.Property.PropertyAddressLine2),
QuotePrice = d.QuotePrice.HasValue ? d.QuotePrice.Value : 0,
ClientContact = ServiceFactory.ContactService.Read(p => p.ContactID == d.ClientContactID).FirstName + " " + ServiceFactory.ContactService.Read(p => p.ContactID == d.ClientContactID).LastName,
IsConverted = d.QuoteRequestStatus.QuoteRequestStatusName == "Accepted" ? "Yes" : "No",
ModifiedDate = d.ModifiedDate ?? DateTime.Now.AddYears(-10)
};
int pastDueCount = list.Count(p => p.ClientDueDate < DateTime.Today);
var instanceReporSouce = new InstanceReportSource();
instanceReporSouce.ReportDocument = new CompletedQuotesReport();
instanceReporSouce.ReportDocument.Reports.First().DataSource = data;
ReportViewer1.ReportSource = instanceReporSouce;
}
}
Now, I want to add some filter to the report.just like the effect that add filter in the design view by using "Fields.XX=parameter.value" expression,For there is no data source in the report now,so it can't be use 'Fields.XX......' expressions.How can i achieve my goal by programs in the backstage. BTW,I try to add parameter by code:
instanceReporSouce.ReportDocument.Reports.First().ReportParameters.Add(new ReportParameter("TotalAccepted", ReportParameterType.String, "TotalAccepted:" + list.Count(p => p.QuoteRequestStatus.QuoteRequestStatusName == acceptedStatus)));
I can get the parameters. but still can't filter data. How can i solve this problem?
Any suggestion is appreciated,
Best regards,
Tang.
private void RegisterByDept_NeedDataSource(object sender, EventArgs e)
{
string groupBy = string.Empty;
string sortBy = string.Empty;
Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
var payoutUID = report.Parameters["payoutUID"].Value.ToString();
// some code here...
}

shift select records in gridview asp.net

hey guys,
i have a gridview which displays 10records per page, now i want to implement shift+click option in my gridview, when user clicks on the first row and press shift key and click on the 5th row, all the rows between 1 and 5(1 and 5 inclusive) should be selected...
can anyone suggest how should i do this in javascript.
I take it back, I found a shift+click multiple select solution for a gridview. All credit goes to mdv over at the asp forums.
var _sPreviousRow = null;
function wsCheckRange(p_oGridView, p_oControl, e) {
var l_sCheckID = p_oControl.id;
var l_aCheckIDParts = l_sCheckID.split(p_oGridView.id);
var l_sCurrentRow = l_aCheckIDParts[1].split('_')[1].substring(3);
var l_oEvent = (window.event) ? event : e;
if (l_oEvent.shiftKey) {
if (_sPreviousRow != null && _sPreviousRow != l_sCurrentRow) {
var l_iFirst = 0, l_iLast = 0;
if (parseInt(_sPreviousRow,10) > parseInt(l_sCurrentRow,10)) {
l_iFirst = parseInt(l_sCurrentRow,10);
l_iLast = parseInt(_sPreviousRow,10);
}
else {
l_iFirst = parseInt(_sPreviousRow,10);
l_iLast = parseInt(l_sCurrentRow,10);
}
for (var i = l_iFirst; i < l_iLast; i++) {
var l_sLastRow = (i <= 9 ? '0' + i : i);
var l_sCtrlNew = l_sCheckID.replace('ctl' + l_sCurrentRow, 'ctl' + l_sLastRow);
var l_oCtrlNew = $get(l_sCtrlNew);
if (l_oCtrlNew) {
l_oCtrlNew.checked = p_oControl.checked;
}
}
}
_sPreviousRow = null;
}
else {
_sPreviousRow = l_sCurrentRow;
}
}

Resources