|
i add auser control which has aformview control to main page dynamically with c# code ,but i set in the page load of the main page the form view with read only mode to bind the data and when i press add section in main page the form view become in insert mode but when i click insert it doesn`t do insert because it make post pack and load the page load which set the form view mode to read only to bind the data which come from the database
the problem is how to set the default mode of form view to insert in the same page which i called the control dynamically with read only mode
find the code html of the user contrl form
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="skills.ascx.cs" Inherits="JobSeeker_skills" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:FormView id="Formviewskills" runat ="server" style="width:100%" DataSourceID="FormViewskillsSDS"
umbDebugShowTrace="true" DataKeyNames="SkillsID" OnItemCreated="Formviewskills_ItemCreated" >
<EditItemTemplate>
<table style="width:100%">
<tr>
<td class="col-md-6">
<asp:label class="link_sgray" id="FirstName" runat="server" >Skills: </asp:label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Skills"
Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>
<br />
<asp:Textbox style="width:100%" id="Skills" class="form-control" runat="server"
Text='<%# Bind("Skills") %>' >
</asp:Textbox>
</td>
</tr>
<tr>
<tr>
<td class="col-md-6">
<asp:label class="link_sgray" id="Label1" runat="server" >Proficiency: </asp:label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="Proficiency"
Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>
<br />
<asp:DropDownList style="width:100%" id="Proficiency" CssClass="dropdown" runat="server" selectedvalue='<%# Bind("Proficiency") %>'
DataSourceID="ProficiencyDDL" DataTextField="Value" DataValueField="ID">
</asp:DropDownList>
</td>
<td class="col-md-6">
<asp:label class="link_sgray" id="Label8" runat="server" >Years of Experience: </asp:label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="YearsofExperienceSkills"
Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>
<br />
<asp:DropDownList style="width:100%" id="YearsofExperienceSkills" CssClass="dropdown" runat="server" selectedvalue='<%# Bind("YearsofExperienceSkills") %>'
DataSourceID="YearsofExperienceSkillsDDL" DataTextField="Value" DataValueField="ID">
</asp:DropDownList>
</td>
<%----%>
</tr>
<tr>
<td colspan="2">
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" CssClass="btn-primary" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" CssClass="btn-primary"/>
</td>
</tr>
</table>
</EditItemTemplate>
<InsertItemTemplate>
<table style="width:100%">
<tr>
<td class="col-md-6">
<asp:label class="link_sgray" id="Skillslbl" runat="server" >Skills: </asp:label>
<%----%>
<br />
<asp:Textbox style="width:100%" id="Skills" class="form-control" runat="server"
Text='<%# Bind("Skills") %>' ></asp:Textbox>
</td>
</tr>
<tr>
<td class="col-md-6">
<asp:label class="link_sgray" id="Label1" runat="server" >Proficiency: </asp:label>
<%----%>
<br />
<asp:DropDownList style="width:100%" id="Proficiency" CssClass="dropdown" runat="server" selectedvalue='<%# Bind("Proficiency") %>'
DataSourceID="ProficiencyDDL" DataTextField="Value" DataValueField="ID">
</asp:DropDownList>
</td>
<td class="col-md-6">
<asp:label class="link_sgray" id="Label8" runat="server" >Years of Experience: </asp:label>
<%----%>
<br />
<asp:DropDownList style="width:100%" id="YearsofExperienceSkills" CssClass="dropdown" runat="server" selectedvalue='<%# Bind("YearsofExperienceSkills") %>'
DataSourceID="YearsofExperienceSkillsDDL" DataTextField="Value" DataValueField="ID">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Button ID="insertButton" runat="server" CommandName="Insert"
Text="Insert" CssClass="btn-primary" ></asp:Button>
<asp:Button ID="insertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" CssClass="btn-primary" ></asp:Button>
</td>
</tr>
</table>
</InsertItemTemplate>
<ItemTemplate>
<table style="width:100%">
<tr>
<td class="col-md-6">
<asp:label class="link_sgray" id="FirstName" runat="server" >Skills: </asp:label>
<br />
<asp:Textbox style="width:100%" id="Skills" class="form-control" runat="server" Enabled="false"
Text='<%# Eval("Skills") %>'></asp:Textbox>
</td>
</tr>
<tr>
<td class="col-md-6">
<asp:label class="link_sgray" id="Label1" runat="server" >Proficiency: </asp:label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="Proficiency"
Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>
<br />
<asp:DropDownList style="width:100%" id="Proficiency" CssClass="dropdown" runat="server" Enabled="false" selectedvalue='<%# Eval("Proficiency") %>'
DataSourceID="ProficiencyDDL" DataTextField="Value" DataValueField="ID">
</asp:DropDownList>
</td>
<td class="col-md-6">
<asp:label class="link_sgray" id="Label8" runat="server" >Years of Experience: </asp:label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="YearsofExperienceSkills"
Display="Dynamic" ErrorMessage="*"></asp:RequiredFieldValidator>
<br />
<asp:DropDownList style="width:100%" id="YearsofExperienceSkills" CssClass="dropdown" Enabled="false" runat="server" selectedvalue='<%# Eval("YearsofExperienceSkills") %>'
DataSourceID="YearsofExperienceSkillsDDL" DataTextField="Value" DataValueField="ID">
</asp:DropDownList>
</td>
<%----%>
</tr>
<tr>
<td>
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="True" CommandName="Edit" Text="Edit" CssClass="btn-primary" />
<asp:LinkButton ID="DeletelButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" CssClass="btn-primary"/>
</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:SqlDataSource ID="ProficiencyDDl" runat="server" ConnectionString="<%$ ConnectionStrings:crms%>"
SelectCommand="SELECT [ID]
,[Value]
FROM [dbo].[StringMap]
where [AttributeName]='Proficiency' "> </asp:SqlDataSource>
<asp:SqlDataSource ID="YearsofExperienceSkillsDDl" runat="server" ConnectionString="<%$ ConnectionStrings:crms%>"
SelectCommand="SELECT [ID]
,[Value]
FROM [dbo].[StringMap]
where [AttributeName]='Years of Experience Skills' "> </asp:SqlDataSource>
<%----%>
<asp:sqldatasource id ="FormViewskillsSDS" runat="Server" ConnectionString="<%$ ConnectionStrings:crms%>"
SelectCommand="
SELECT SkillsID,
[Skills] ,
[Proficiency] ,
[YearsofExperienceSkills]
FROM Skills
inner join StringMap SMSP on SMSP.ID= Skills.Proficiency
and SMSP.AttributeName='Proficiency'
inner join StringMap SMYOES on SMYOES.ID= Skills.YearsofExperienceSkills
and SMYOES.AttributeName='Years of Experience Skills'
where ApplicantID=@ApplicantID and
SkillsID= @SkillsID
"
InsertCommand="Insert into [Skills] ( Skills ,
Proficiency ,
YearsofExperienceSkills
, ApplicantID ) VALUES ( @Skills, @Proficiency , @YearsofExperienceSkills , @ApplicantID); select @SkillsID = SCOPE_IDENTITY() "
DeleteCommand="DELETE FROM [Skills] WHERE [SkillsID] = @SkillsID"
UpdateCommand="UPDATE Skills
SET
Skills= @Skills
,Proficiency= @Proficiency
, YearsofExperienceSkills= @YearsofExperienceSkills
WHERE ApplicantID = @ApplicantID and
SkillsID= @SkillsID">
<SelectParameters>
<asp:SessionParameter Name="ApplicantID" Type="Int32" SessionField="ApplicantID" />
<asp:Parameter Name="SkillsID" Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:ControlParameter Name="Skills" ControlID="Formviewskills$Skills" Type="string" PropertyName="Text" />
<asp:ControlParameter Name="Proficiency" ControlID="Formviewskills$Proficiency" Type="int32" PropertyName="SelectedValue" />
<asp:ControlParameter Name="YearsofExperienceSkills" ControlID="Formviewskills$YearsofExperienceSkills" Type="int32" PropertyName="SelectedValue" />
<asp:SessionParameter Name="ApplicantID" Type="Int32" SessionField="ApplicantID" />
<asp:parameter Direction="Output" Name="SkillsID" Type="Int32" />
</InsertParameters>
<DeleteParameters>
<asp:SessionParameter Name="SkillsID" Type="Int32" SessionField="SkillsID" />
</DeleteParameters>
<UpdateParameters>
<asp:ControlParameter Name="Skills" ControlID="Formviewskills$Skills" Type="String" PropertyName="text"/>
<asp:ControlParameter Name="Proficiency" ControlID="Formviewskills$Proficiency" Type="int32" PropertyName="SelectedValue" />
<asp:ControlParameter Name="YearsofExperienceSkills" ControlID="Formviewskills$YearsofExperienceSkills" Type="int32" PropertyName="SelectedValue" />
<asp:SessionParameter Name="ApplicantID" Type="Int32" SessionField="ApplicantID" />
</UpdateParameters>
</asp:sqldatasource>
and the dynamically code add in the page load of main page is
Session["FormMode"] = false;
da = new SqlDataAdapter("select SkillsID from Skills Where ApplicantID='" + ApplicantID + "'", con);
con.Open();
ds = new DataSet();
da.Fill(ds, "Jobs");
DataTable SkillsTable = ds.Tables[0];
if (SkillsTable.Rows.Count > 0)
{
int i = 1;
foreach (DataRow row in SkillsTable.Rows)
{
DataColumn col = SkillsTable.Columns["SkillsID"];
Session["SkillsID"] = row[col].ToString();
HtmlGenericControl DivSkills = new HtmlGenericControl("div");
DivSkills.Attributes.Add("class", "class=panel - body");
DivSkills.Attributes.Add("id", (i).ToString());
Skillspnl.Controls.Add(DivSkills);
System.Web.UI.UserControl uc3 = (System.Web.UI.UserControl)Page.LoadControl("~/JobSeeker/skills.ascx");
FormView SkillsFV = uc3.FindControl("Formviewskills") as FormView;
SkillsFV.DefaultMode = FormViewMode.readonly;
SqlDataSource SqlSkills = uc3.FindControl("FormViewskillsSDS") as SqlDataSource;
SqlSkills.SelectParameters["SkillsID"].DefaultValue = row[col].ToString();
SqlSkills.DataBind();
DivSkills.Controls.Add(uc3);
i++;
}
}
|
|
|
|
|
|
OK
modified 6-Apr-17 12:30pm.
|
|
|
|
|
Right-click the project in the Solution Explorer, and choose Add->Reference. You should be able to figure out the dialog box from there.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Message Closed
modified 6-Apr-17 12:27pm.
|
|
|
|
|
Try rebuilding the project(s) that contains the types you are looking for.
Otherwise you're going to have to provide a lot more information. We can't see your screen or your projects to know what's wrong.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Message Removed
modified 2-Sep-16 14:29pm.
|
|
|
|
|
Hi All,
I deployed my asp.net application to IIS7 on server while loading data I am getting below error.
SQL1159 Initialization error with DB2 .NET Data Provider, reason code 7, tokens 9.5.4.DEF.2, SOFTWARE\IBM\DB2\InstalledCopies
StackTrace : at IBM.Data.DB2.DB2ConnPool.Open(DB2Connection connection, String& szConnectionString, DB2ConnSettings& ppSettings, Object& ppConn)
at IBM.Data.DB2.DB2Connection.Open()
====================================================
i compiled my application in 32bit machine and server is 64bit machine.
I did multiple setting in IIS like
1. "Enable 32bit application"
2. %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
3. Copying dll manually to GAC/C:windows/Assembly folder
4. Given full permission to sqllib folder.
5. I also tried changing to NetworkService.
not sure but still its giving above error.
Do i need to install 32 bit IBM Db2.net provider??
as 64 bit provider already installed on server.
Per my analysis do i need to install "IBM Data ServerProvider for .NET "??
Please advice i tried almost every solution .
Thanks
|
|
|
|
|
Tej_dev wrote: Please advice i tried almost every solution .
Did you try posting your problem in an appropriate forum? I don't see how this is anyway related to a C# issue. This appears to be an IIS or database administration problem and nothing to do with this forum.
|
|
|
|
|
If your application is compiled 32-bit it can ONLY work with 32-bit libraries, such as DB2.
If all you have on the server is the 64-bti DB2 client and provider, your application MUST be compiled as AnyCPU or explicitly as a 64-bit app. I would highly suggest switching it to explicitly 64-bit.
|
|
|
|
|
I am still having same issue , i compiled my application on 64 bit machine added 64bit IBM.data.Db2 dll and deployed code on IIS7
getting same error. please advice
Exception Message :SQL1159 Initialization error with DB2 .NET Data Provider, reason code 7, tokens 9.5.4.DEF.2, SOFTWARE\IBM\DB2\InstalledCopies
StackTrace : at IBM.Data.DB2.DB2ConnPool.Open(DB2Connection connection, String& szConnectionString, DB2ConnSettings& ppSettings, Object& ppConn)
at IBM.Data.DB2.DB2Connection.Open()
at DataAccessLayer.DataAccessLayer.getSourceDataDetails(String sourceDatabaseName)
at BusinessLayer.BusinessLayer.GetSourceDBUserNames(String sourceDatabaseName)
|
|
|
|
|
You don't have to compile it on a 64-bit machine. You DO have to go into the Project Properties, Build tab, and make sure that "Platform target" is set to "x64".
After that, you have to make sure your connection string, as deployed onto the server, is accurate.
|
|
|
|
|
I am new in EF. I mostly use ADO.Net to interact with DB. So learning EF code first.
Just see a below code. Post and blog class which has one-to-many relation I guess...........am I right?
public class Blog
{
public int BlogId { get; set; }
public string Name { get; set; }
public virtual List<Post> Posts { get; set; }
}
public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public virtual Blog Blog { get; set; }
}
why blog class has one virtual property list type of Post?
And same way why post class has one virtual property type of Blog?
if we remove the virtual keyword only then what will happen?
how virtual keyword create relation?
why virtual keyword has been used in two class?
Please answer my all questions point wise in details.
tbhattacharjee
|
|
|
|
|
Did you even bother reading the answers the last time you posted about this[^]?
This space for rent
|
|
|
|
|
Hi everyone,
I would like your opinion on the following. I have an abstract base class with a property:
public abstract class BaseClass
{
public abstract double SomeProperty { get; set; }
}
I have several derived classes based on it. Some of these derived classes have a fixed value for the property, and some do not. How would you implement the derived classes with the fixed value for SomeProperty? Maybe something like this:
public class DerivedClass : BaseClass
{
private double _fixedValue;
public override double SomeProperty
{
get { return _fixedValue; }
set { _fixedValue = 1d; }
}
}
The problem with the above implementation is that I can access the property from the outside and the code makes me think I can modify the value, but it will always give me the same result. This is not what I want, obviously.
Maybe I need to rethink how to set up the base class? If so, do you have any suggestions?
|
|
|
|
|
You don't actually have to implement anything inside the setter so it's perfectly possible to do this:
public class DerivedClass : BaseClass
{
public override double SomeProperty
{
get { return 1d; }
set { }
}
}
This space for rent
|
|
|
|
|
As Pete says, you don't have to put anything in the setter.
But I must admit, I don't like that, as you can still write:
DerivedClass dc = new DerivedClass();
dc.SomeProperty = 23.0;
And it will appear to work - there is no compile or runtime error here which is potentially confusing:
public class DerivedClass2 : BaseClass
{
public override double SomeProperty { get; set; }
}
Allows:
BaseClass bc = new DerivedClass();
bc.SomeProperty = 23.0;
bc = new DerivedClass2();
bc.SomeProperty = 23.0;
Which doesn't do the same thing in both cases.
You could throw an exception in the "unwanted" setter:
public class DerivedClass : BaseClass
{
public override double SomeProperty
{
get { return 1d; }
set { throw new ApplicationException("Cannot set SomeProperty of DerivedClass - it is read only"); }
}
}
But that just moves the problem to runtime and I don't like that either.
It might be better to make the Setter protected :
public abstract class BaseClass
{
public abstract double SomeProperty { get; protected set; }
}
Because at least then you are restricting the confusion to classes that are directly involved, instead of letting the rest of the world get confused as well.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I learn something: I happy. You good.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
"If you learn something new every day, you can teach something new every day." --- Martha Stewart
My wife learns something new from me everyday. She thinks it's important to learn from her mistakes.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hello,
I have problem with insert timestamp to PDF.
On line Array.Copy(pk, 0, outc, 0, pk.Length); is error because outc.Length = 4096, but pk.Length = 7541. Metod DejCasoveRazitko work correctly.
P.S. Sorry, my English is bad
private const String ID_TIME_STAMP_TOKEN = "1.2.840.113549.1.9.16.2.14";
public void PodepisPdfCer(string SouborPDF, string OtiskCertifikatu)
{
var store = new System.Security.Cryptography.X509Certificates.X509Store(System.Security.Cryptography.X509Certificates.StoreName.My, System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser);
store.Open(System.Security.Cryptography.X509Certificates.OpenFlags.ReadOnly);
string thumbprint = OtiskCertifikatu.Replace(" ", "").ToUpperInvariant();
if (thumbprint[0] == 8206)
{
thumbprint = thumbprint.Substring(1);
}
var certs = store.Certificates.Find(System.Security.Cryptography.X509Certificates.X509FindType.FindByThumbprint, thumbprint, true);
store.Close();
if (certs.Count == 0)
{
MessageBox.Show("Nelze najít určený certifikát v Current user certificate store!", "Sign PDF", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
byte[] pdfData = File.ReadAllBytes(SouborPDF);
using (MemoryStream stream = new MemoryStream())
{
var reader = new PdfReader(pdfData);
var stp = PdfStamper.CreateSignature(reader, stream, '\0');
var sap = stp.SignatureAppearance;
stp.SetEncryption(null,
Guid.NewGuid().ToByteArray(),
PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_SCREENREADERS,
PdfWriter.ENCRYPTION_AES_256);
var cp = new Org.BouncyCastle.X509.X509CertificateParser();
var certChain = new Org.BouncyCastle.X509.X509Certificate[] { cp.ReadCertificate(certs[0].RawData) };
sap.SetCrypto(null, certChain, null, PdfSignatureAppearance.WINCER_SIGNED);
BaseFont helvetica = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
iTextSharp.text.Font font = new iTextSharp.text.Font(helvetica, 12, iTextSharp.text.Font.NORMAL);
sap.Layer2Font = font;
var dic = new PdfSignature(PdfName.ADOBE_PPKMS, PdfName.ADBE_PKCS7_SHA1);
dic.Date = new PdfDate(sap.SignDate);
dic.Name = certs[0].Subject;
if (sap.Reason != null)
{
dic.Reason = sap.Reason;
}
if (sap.Location != null)
{
dic.Location = sap.Location;
}
sap.CryptoDictionary = dic;
int csize = 4096;
var reservedSpace = new Dictionary<PdfName, int>();
reservedSpace[PdfName.CONTENTS] = csize * 2 + 2;
sap.PreClose(reservedSpace);
System.Security.Cryptography.HashAlgorithm sha = new System.Security.Cryptography.SHA256CryptoServiceProvider();
var sapStream = sap.GetRangeStream();
int read = 0;
byte[] buff = new byte[8192];
while ((read = sapStream.Read(buff, 0, 8192)) > 0)
{
sha.TransformBlock(buff, 0, read, buff, 0);
}
sha.TransformFinalBlock(buff, 0, 0);
System.Security.Cryptography.Pkcs.ContentInfo contentInfo = new System.Security.Cryptography.Pkcs.ContentInfo(sha.Hash);
System.Security.Cryptography.Pkcs.SignedCms signedCms = new System.Security.Cryptography.Pkcs.SignedCms(contentInfo, false);
System.Security.Cryptography.Pkcs.CmsSigner cmsSigner = new System.Security.Cryptography.Pkcs.CmsSigner(certs[0]);
cmsSigner.IncludeOption = System.Security.Cryptography.X509Certificates.X509IncludeOption.ExcludeRoot;
if (!String.IsNullOrEmpty(textBox_ServerCasovehoRazitka.Text.Trim()))
{
try
{
System.Security.Cryptography.AsnEncodedData timeData = new System.Security.Cryptography.Pkcs.Pkcs9AttributeObject(ID_TIME_STAMP_TOKEN,
DejCasoveRazitko(stream.GetBuffer(), textBox_ServerCasovehoRazitka.Text)
);
cmsSigner.UnsignedAttributes.Add(timeData);
}
catch (Exception e)
{
MessageBox.Show("Chyba TSA!\n" + e.Message);
}
}
signedCms.ComputeSignature(cmsSigner, false);
byte[] pk = signedCms.Encode();
byte[] outc = new byte[csize];
Array.Copy(pk, 0, outc, 0, pk.Length);
PdfDictionary certificateDictionary = new PdfDictionary();
sap.Close(certificateDictionary);
stp.Close();
reader.Close();
byte[] signedData = stream.GetBuffer();
File.WriteAllBytes(SouborPDF, signedData);
}
}
static protected byte[] DejCasoveRazitko(byte[] PDF, string ServerTSA)
{
System.Security.Cryptography.SHA256Managed hashString = new System.Security.Cryptography.SHA256Managed();
string hex = "";
var hashValue = hashString.ComputeHash(PDF);
foreach (byte x in hashValue)
{
hex += String.Format("{0:x2}", x);
}
NotservisTSA.GetTimeStampRequest Request = new NotservisTSA.GetTimeStampRequest(new NotservisTSA.GetTimeStampRequestBody(hex, 0));
NotservisTSA.Print2PDF_WebServiceSoap Soap = new NotservisTSA.Print2PDF_WebServiceSoapClient();
((NotservisTSA.Print2PDF_WebServiceSoapClient)Soap).Endpoint.Address = new System.ServiceModel.EndpointAddress(new Uri(ServerTSA + "/Default.asmx"));
PodepsaniPDF.NotservisTSA.GetTimeStampResponse Response = Soap.GetTimeStamp(Request);
byte[] responseBytes = Encoding.ASCII.GetBytes(Response.Body.GetTimeStampResult);
if(!String.IsNullOrEmpty(Response.Body.Error))
MessageBox.Show(Response.Body.Error, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error);
string base64String = Encoding.UTF8.GetString(responseBytes, 0, responseBytes.Length);
return Convert.FromBase64String(base64String);
}
|
|
|
|
|
Hi Team,
Could someone suggest ideal way to submit 100s of rows from UI to db ?
i think better approach would be to Prepare XML and send it to DB.
Any other ideas are welcome.
Thanks,
Giri
|
|
|
|
|
|
Depends on the database-server.
In the case of SQLite, you'd be better of doing 100 inserts wrapped in a transaction.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello all. I have a background worker that executes a query against an SQL Server database. The user clicks a button and the query runs, then the results of the query go into a datagrid. The users are requesting a Cancel button for the query because the queries can take a very long time to run. So when the user clicks the Run Query button, a small form with a Cancel Button opens. If the user clicks the button, DialogueResult.Cancel is returned and I execute CancelAsync().
Meanwhile, in my DoWork thread, I am preparing to run the query. When I run the query, I execute
adapter3.Fill(GlobalData.g_queryData);
So, there is no loop. Most of the forums I have seen tell you to check Backgroundworker.CancellationPending. The problem is that I am not running in a loop.
So, can someone suggest maybe another approach to canceling a query that is currently running?
Thanks,
David
using (SqlConnection connection = new SqlConnection(GlobalStr.sqlConnStringMetadata))
{
try
{
connection.Open();
SqlTransaction Transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted);
using (SqlCommand testQuery = new SqlCommand(GlobalStr.previewQueryString, connection))
{
testQuery.CommandTimeout = m_QueryTimeout;
testQuery.Transaction = Transaction;
using (SqlDataAdapter adapter3 = new SqlDataAdapter(testQuery))
{
adapter3.Fill(GlobalData.g_queryData);
DataSetViewer dsv = new DataSetViewer();
dsv.SetSource(GlobalData.g_queryData);
string strClassification = string.Format("{0} {1}", GlobalStr.g_classification, GlobalStr.g_releaseability);
dsv.setClassification(strClassification);
Cursor.Current = Cursors.Default;
dsv.ShowDialog();
}
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("The query test failed: " + ex.Message);
return;
}
}
|
|
|
|
|
I have accomplished a similar task in the past using a variation of this code:
public sealed class ExtendedBackgroundWorker : BackgroundWorker
{
private Thread thread;
public void Stop()
{
thread?.Abort();
thread = null;
}
protected override void OnDoWork(DoWorkEventArgs eventArgs)
{
thread = Thread.CurrentThread;
try
{
base.OnDoWork(eventArgs);
}
catch (ThreadAbortException threadAbort)
{
Debug.WriteLine("ExtendedBackgroundWorker has been aborted");
Thread.ResetAbort();
eventArgs.Cancel = true;
}
}
} With this, you're going to Abort the Thread. Now, an Abort is normally a bad method to call (there are various resources you can look up about why it's not recommended), but we're going to handle it in a controlled manner. When the thread is aborted, a ThreadAbortException is raised so, in our OnDoWork handler, we want to Cancel the DoWorkEventArgs and reset the Abort so that it doesn't destabilise our system. Now, you have a background worker that can be killed from the calling code. By the way, I call the method Stop rather than Abort because while this code is carefully written to prevent Abort issues, I don't want people to get into the habit of calling Abort wherever they see thread codes. By hiding the implementation, I'm hiding the idea that Abort should be called.
This space for rent
|
|
|
|
|