.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
MarieAdela
Imran Ghani
Post New Web Links

using System.Reflection to saving to database

Posted By:      Posted Date: October 28, 2010    Points: 0   Category :Windows Application
 

Hello guy!

 

I am having challenges saving multiple row to my database using reflection. Each time I cmd.ExecuteNonQuery(), I get the message 'The variable name '@referenceID' has already been declared. Variable names must be unique within a query batch or stored procedure.'

What should i do to resolve this?




View Complete Post


More Related Resource Links

Does this look correct for saving a file/ new record to a database

  

So thank you for all your help so far, So I think i got this right,
but would like for you all to look it over to see if there is any
areas I might run into trouble with:

//using asp.net mvc 2
the table (sql server 2005, using entities framework)
"Pattern_Media"
table fields
"Pattern_Media_GUID  uniqueid 
"Pattern_GUID  uniqueid
"Media varbinary(max)  
"height int
"Width int
"Media_Type String (50)


the form:
<h2> Add Media to this pattern</h2>
<% Html.EnableClientValidation(); %>
<% Html.BeginForm("AddMedia", "Pattern", new { id= Model.Pattern_Guid} , FormMethod.Post, new {enctype = "multipart/form-data"}); %>
   
    <%: Html.Label("height") %>
    <%: Html.TextBox("height") %>

    <%: Html.Label("width") %>
    <%: Html.TextBox("width") %>

    <%: Html.Label("Media") %>
    <input type="file" id="Media" name="Media" />
   
    <input type="submit" name=

Saving textbox data to MySql database in asp.net

  

Hi dear coders

though a very simple question to ask, but please tell me how to save and retrieve data in/from my textboxes to/from database (MYSQL) on submit button click.

i know its a very simple task but i cant make it done, so i request you to please send me some working example link or post any helpful code here in asp.net


i will be highly thankful for any kind help from you geniuses.


regards

alok


Saving SOAP to Database

  
Hi All, 

Web Services are very new to me and for the life of me I can not find any info on how to save a soap call/response to the database for a web service.

I did find how to trace them but not save it.

Part of my issue may be that, I am not building a soap envelope for the send. The service I am calling uses different methods to post to itself, e.g.  

api.Execute, api.Create, api.Update and api.Retrieve.

I think these methods are building the envelope for me. If I 'Go to definition' on the Execute method it takes me to the References.cs codebehind page in the application web service for this code.

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("Execute", RequestElementName="ExecuteRequestMsg", RequestNamespace="http://exacttarget.com/wsdl/partnerAPI", ResponseElementName="ExecuteResponseMsg", ResponseNamespace="http://exacttarget.com/wsdl/partnerAPI", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        [return: System.Xml.Serialization.XmlElementAttribute("OverallStatus")

showing modalpopup and saving data to database simultaneously using ajaxtoolkit and javascript

  
hi,i have a button ,i want that when i click on that button the data should be saved in the database as well as at the same time a modal popup should display the customerid .i have written the code as <asp:button id="save1" runat="server" onclick="Button4_Click" style=""z-index:" mode="hold" xmlns:asp="#unknown" /> left: 740px; position: absolute; top: 304px" Text="save"/> <asp:panel id="panel" runat="server" xmlns:asp="#unknown">  /asp:Panel> <ajaxtoolkit:modalpopupextender id="MPE" runat="server" targetcontrolid="save1" xmlns:ajaxtoolkit="#unknown"> PopupControlID="panel" DropShadow="true" BackgroundCssClass="modalBackground/> protected void Button4_Click(object sender, EventArgs e) { string id = TextBox1.Text; string name = TextBox2.Text; string cn = "Data Source=hcl;Initial Catalog=mydata;Integrated Security=True"; SqlConnection con = new SqlConnection(cn); SqlCommand cmd = new SqlCommand("insert into customer values (@id,@name)", con); con.Open(); cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@id", id); cmd.Parameters.Add("@name",name); cmd.ExecuteNonQuery(); con.Close(); CUSTID.Text = id.ToString(); MPE.Show(); }

Access Database from another system..

  
I am using SqlExpress 2008, I have created a instance named "INSTANCEA" in one system as windows authontification mode and sql server authentification mode..  Its working well... But I can't access my instance from another system... while accessing the instance i have got the following message.... Cannot connect to NODEA\INSTANCEA. ------------------------------ ADDITIONAL INFORMATION: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 28 - Server doesn't support requested protocol) (Microsoft SQL Server, Error: -1)

Hide system database in SQL Management Studio

  
I am using SQL server 2008 . What i all want is to create a uses that can only see the ABCDatabase in Management studio onced login. And to achieve that:1- I have created a new user.2- Deny View all database right to that user.3-Set that user as Owner of ABCDatabaseNow on login that user cannot see other databases but still able to see the system databases. How can i hide those system databases from that user?

need a simple login page cus my hosting provider system wont allow me to have more than one database

  
I dont really write html code too well  but I manged to get my web site developed and deployed using the built in features such as drag n drop, master page and user account authentication that make web developing almost a codeless experience. However; my hosting provider system wont allow me to have more than one database, this causes problems becasue when I developed my web app using vb2010 web developer (asp.net v2) I used the built in web config tool to manage users for my site, now after I deployed to my domain it all worked ok with the exeption of the login page, when I tried to log in the system threw a error message saying "database not found." or a page of "gobble-dee-gook" that says the same thing When I contacted support (my hosting provider) they said i have to create a table of users in my database file via 2008 sql server, thats ok I can do that, but my real problem is I dont know how to write appropriate code to reference the table. So heres my problem:  I just want to have some kind of login page with a couple of txtboxes and a click button that maybe using the VB code behind or html checks the input variables "username" "password" against something that is hard coded into vb a string variable or a constant and then branches to Mainmenu.aspx if successfull. I just need it real simple, no fancy stuff just a login s

dataset not saving to database - what am I not doing? :((

  
Hello.  Please help me with this one if you have a few mins.  I think I'm overlooking something silly... I have a "hello world" database project.  A mdf database with 1 table "users", the table has 2 columns userid & username (both varchar(50)).  I added a dataset called Database1Dataset.xsd.  I drag the table onto it and it creates the "users" datatable.  I checked it to see if it created the insert and update commands and it has.   On my form I have 2 buttons, one for read and the other for write/save. The read button works and I can see the test records in the database; Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim da As New Database1DataSetTableAdapters.usersTableAdapter Dim dt As New Database1DataSet.usersDataTable da.Fill(dt) For Each dr In dt TextBox1.Text += dr.userid & " - " & dr.username & vbCrLf Next End Sub   The second button should add a new record and save it down to the database but this does not work.  Somehow the changes are not being commited and saved. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim dt As New Database1DataSet.usersDataTable

what is the better design for location of system database data / log files and user data/log file,

  
is there a guideline for better performance for system database data location log location, like tempdb location etc. also better location for user databases/data and log.

System.Reflection: How to use the name of fields within classes to get the values?

  
Hey there, I have  a class defiend as follows:public class VisitorStat { public int? PageViews { get; set; } public int? Visits { get; set; } public int? Visitors { get; set; } ... } At some point in my program, I need to gather the  Visitor stats and create a report table.List<VisitorStat> visitorStats = GetVisitorStats(startDate, endDate);   My issue is this: Because there are many rows in the table, rather than hard coding the name for each row as: "PageViews", "Visits", "Visitors"... I want a way to use the name of the fields in the class to create the Row name and insert the appropriate values. I found out about System.Reflection and wrote the following:  Type type = typeof(VisitorStat); // Get type pointer FieldInfo[] fields = type.GetFields(); // Obtain all fields //Start creating a row for each field in the class foreach (var field in fields) // Loop through fields { object temp = field.GetValue(null); //The first cell in the Row contains the name of the field Cell Col2Row1 = new Cell(new Paragraph(field.Name)); PdfTable.AddCell(Col2Row1); //for item returned when calling the function to get t

How To Update Database When The System Shut Down By Light Problem

  
Hi,I want to update the User LoggedIn Status to 'False', when the system shut down by light problem, or when the user click the 'Browser Close Button'Please help me in details.Thanks in advance.

Code in an event handler not working when used with system reflection.

  
Hi, I am presently writing an application that uses an MDI form with a ToolStrip on it. I have the need to build the menu items dynamically using an XML file. The format of the XML file is as follows: <ContextMenu EventHandlerHost="vFrmPDUsetup"> <!-- These styles will be applied to the menu items. Individual menu item styles can be override by defining as an attibute to the specific menu item, see below --> <Style> <MenuStripBackColour>Transparent</MenuStripBackColour> <BackColour></BackColour> <ForeColour>Chartreuse</ForeColour> <BackImage></BackImage> <!-- Must exist in Images folder --> <FontName>Tahoma</FontName> <FontSize>10</FontSize> <FontStyle>Bold</FontStyle> </Style> <!-- Attributes: Key = Resource Key name in resource file Image = image to display before text, image must exist in Images folder BackImage = background image, image must exist in Images folder BackColour = background colour as colour name ForeColour = foreground colour as colour name FontSize = size of font as value Seperator = add a menu seperator OnClick = click event pointing to the event handler method which must be defined as the MenuItem_ + <attibute value> &

Unhandled exception in XAML editor from control that accesses database. - "System.Data.SqlServerCe.S

  

Hello,

Im having a bit of difficulty with some WPF/C#/SQL Server CE code.

I have a WPF User Control with the following line of code in the constructor:

MyDatabase database = new
 MyDatabase("Data Source=|DataDirectory|\\MyDatabase.sdf"
 );

where MyDatabase is a class generated using SQLMetal.exe from MyDatabase.sdf.

 

When I added this control to other controls, the application runs fine and I'm able to access my database. When I try to edit these parent controls,  the XAML editor throws the following error:

 

>System.Data.SqlServerCe.SqlCeException
>The database file cannot be found. Check the path to the database. [ Data Source = D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MyDatabase.sdf ]

 

Why does the XAML editor redirect my DataDirectory to "D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\" and why does the XAML editor execute my database access code?

 

How can I fix this so I can use this control in a XAML editor?

Thanks,

Greg S.

 


Unhandled exception in XAML editor from control that accesses database. - "System.Data.SqlServerCe.S

  

Hello,

Im having a bit of difficulty with some WPF/C#/SQL Server CE code.

I have a WPF User Control with the following line of code in the constructor:

MyDatabase database = new
 MyDatabase("Data Source=|DataDirectory|\\MyDatabase.sdf"
 );

where MyDatabase is a class generated using SQLMetal.exe from MyDatabase.sdf.

 

When I added this control to other controls, the application runs fine and I'm able to access my database. When I try to edit these parent controls,  the XAML editor throws the following error:

 

>System.Data.SqlServerCe.SqlCeException
>The database file cannot be found. Check the path to the database. [ Data Source = D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MyDatabase.sdf ]

 

Why does the XAML editor redirect my DataDirectory to "D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\" and why does the XAML editor execute my database access code?

 

How can I fix this so I can use this control in a XAML editor?

Thanks,

Greg S.

 


Updating the viewstate object before saving it to the database

  

I have overridden the following methods:

LoadPageStateFromPersistenceMedium()

SavePageStateToPersistenceMedium(object viewState) 

in a class that my page derives from, so that the viewstate can be stored in DB.

Now, on page_load of my page, I am checking what control caused a postback & based on that I am forcing execution of 2 button click events in a row (by overloading those click events & calling them explicitely), but the behaviour I want is as if the execution of those 2 button click events went through the regular page life cycle.

Here is the sequence of events that happen in typical page life cycle & notice I want to alter behaviour at step 4 (on load):

1) Initialization

2) LoadViewStateData (here the viewstate is loaded from my database using the overridden LoadPageStateFromPersistenceMedium)

3) LoadPostBackData

4) Load

Here, I would like to force execution of 2 button_click events based on whether a particular control posted back.

       4.1) imgBtnPrev5_Click()

       4.2) imgBtnPrev4_Click()

Now, when the imgBtnPrev5_Click() is executed, the viewstate is already loaded, so we are fine. But after execution of imgBtnPrev5_Click(), I would like to update the viewstate object in memory & then call the o

How to identify a system database

  

Hi,

please can you help me how to 100% identify system database by T-SQL? Please not by the name. I think, there has to be any official way. Thanks.


Michal Neuwirth | personal developer blog (CZ) | blog on Kentico Devnet(EN)

Using Reflection to get System.ComponentModel.DisplayName or Description

  
I have a class and on the properties I have assigned the attributes System.ComponentModel.DisplayName and System.ComponentModel.Description.  Using reflection I can't seem to retrieve these attribute values.  How can I do this?
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend