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

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

how to insert Value from C # code To SQL string?

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :.NET Framework


I have connection string to sql and text Value wich I get from combobox no I wont to insert this Value to connection string how I do that correctly?

there is a code.

var value1 = CorporationCode1.Text;              

                DataSet ds2 = new DataSet();

                SqlConnection con2 = new SqlConnection("Data Source=DAN-PC;Initial Catalog=DMS_VEOLIA;Integrated Security=True");

View Complete Post

More Related Resource Links

how to insert Value from C # code To SQL string?



I have connection string to sql and text Value wich I get from combobox no I wont to insert this Value to connection string how I do that correctly?

there is a code.

var value1 = CorporationCode1.Text;              

                DataSet ds2 = new DataSet();

                SqlConnection con2 = new SqlConnection("Data Source=DAN-PC;Initial Catalog=DMS_VEOLIA;Integrated Security=True");

C# Insert string from code behind to javascript function


Hi I am using the FullCalendar plugin and I am wanting to load events from the db to the page.

In my codebehind I have a string built up of the events which need to be included.

And I need it to be inserted into the javascript function in the position shown below:

Any help???

For example:

string Calevent = "{ title: 'Click for Google', start: new Date(y, m, 28), end: new Date(y, m, 29),url: 'http://google.com/'}";

$(document).ready(function() {
        var date = new Date();
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();

        var calendar = $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'

Writing connection string in web.config file by code or dynamically

I want to write connection string in web.config file of my application by code. If anyone know the way or code just help me..NET,C#,SQL SERVER

how to insert null or empty string to datetime var ?

hi i get data from xml file and sometime the date is empty. i have this code:     try { TimeTo = Convert.ToDateTime(R[15].ToString()); }         catch { TimeTo = null ; } but i got error because i cant insert null to datetime var what i can do ? thak's in advance

SharePoint Dataview Insert New Mode - Defaulting a Required Column to a Query String Parameter Valu

I've got a SharePoint DataView with an insert button. there is a required lookup column I want to default to the value of Querystring Value during new mode.  Can I do this in the generated code below? I tried replacing @ApplicantId with @QSApplicantID.. and  tried string(@QSApplicantID) too.. no luck gave me an error: The data source control failed to execute the insert command. Could it be that QSApplicantID (which I've used in my DataView Datasource filter with no problem) is not available during the insert? I think I can do what I want in Javascript but was hoping I could instead right in the XSL markup. *my query string parameter**     ParameterBinding Name="QSApplicantID" Location="QueryString(ID)" DefaultValue="2222222"/ **the new form** SharePoint:FormField runat="server" id="ff4{$Pos}" ControlMode="New" FieldName="ApplicantId" __designer:bind="{ddwrt:DataBind('i',concat('ff4',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@ApplicantId')}" / **the link** a href="javascript: {ddwrt:GenFireServerEvent('__cancel;dvt_1_form_insertmode={1}')}">Insert</a Thanks for any help or information!

How to return a string value to code behind?

How to get a string value from a stored procedure to the code behind of ASP.net with C#

Pass string to Javascript function from code-behind...



I'm trying to send a error message to a javascript function from code-behind, but it's not working. When the javascript is executed the output error is: [object Object]

Here's my Javascript:

function Error(error) 
            document.getElementById("<%= errorText.ClientID %>").innerText = error;

And my C#:

        textError = "This is not working!!!";

        ScriptManager.RegisterStartupScript(Page, this.GetType(), "Error", "javascript:Error('" + textError + "');", true);                

Even if i pass the string instead of the 'textError' variable i still get the same error :(

Can anyone help me?

Calculating string length in points from code behind on the WEB server


Hi, I'm using the follow code to calculate some text by Font and Font Size:


private decimal CalculateTextLength(string text, bool isTitle)
            Font DrawFont = null;
            Graphics DrawGraphics = null;
            Bitmap TextBitmap = null;
                // start with empty bitmap, get it's graphic's object
                // and choose a font
                TextBitmap = new Bitmap(1, 1);
                DrawGraphics = Graphics.FromImage(TextBitmap);

XmlDataProvider and XMLDocument loaded as string from code behind


I am trying to load an XML string in a XML document and bind this XML document using the XmlDataProvider to a control.

However, I get the error message "The resource 'xmldata' could not be resolved." In code-behind this is how the XML document is loaded with a string at runtime: xmlDoc.LoadXml(e.data)


Any hints on how to solve the issue would be highly appreciated.


Thank you



<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" >

 <Window.Resources> <XmlDataProvider x:Key="xmlData" Document="xmlDoc" XPath="./ReportSnapshot" >



<Grid Name="grid1" DataContext="xmldoc">

 <TextBox Name="textbox1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Text="{Binding Source={StaticResource xmldata}, BindsDirectlyToSource=True, Path=Source, UpdateSourceTrigger=PropertyChanged}">




Sql Insert in my code behind is inserting extra spaces


Hi Folks

I have a insert inserting some stuff and for some odd reason 2 of my columns are getting inserted with extra spaces.

I have the strings .trim() but its not triming the insert. Oddly enough I am creating a directory on the fly using one of my same strings and its not creating the extra spaces when it does that.

 String UserName = User.Identity.Name.Trim();
                String OrgName = LabelOrg.Text.Trim();
                String path = Server.MapPath("~/Uploads/Documents/" + OrgName + "/" + DropDownList1.SelectedValue + "/" + DropDownListDocType.SelectedValue + "/");

cmd.CommandText = "INSERT INTO tblDocuments (coopcode, locationid, doctypecode, docname, dateuploaded, docstorename, username) VALUES('" + OrgName + "','" + DropDownList1.SelectedValue + "','" + DropDownListDocType.SelectedValue + "','" + FileUpload1.FileName + "','" + DateTime.Now + "','" + dateString + "-" + FileUpload1.FileName + "','" + UserName + "')";

The coopcode and locationid is the ones adding extra spaces. I am using OrgName for the coopcode 

Help :)

Thanks in advance

Upload and insert csv data into SQL from code behind


In my orginal post i asked the question to handle this within the .Net side.
I was trying to stay away from using SSIS package, and with help from another member, i was able to get the process to work with an excel spreadsheet.

But part of my project requires us to allow .csv files.. so my question is how can i modify the code i have now for the excel to work with a .csv file?
You can find the current code in my original post here: http://forums.asp.net/t/1584668.aspx

I not sure what the best solution is for the end result.. I was reading somewhere online that you can right the data from the file to a datalist or gridview so you can present the user with a view of what is being uploaded, then use that datacontrol to insert into SQL.

In my current code, im uploading the file, then using that file to do the insert. This works fine for .xls files.. but i need to accomplish the same thing for a .csv file.

Now not sure if we should force the file to include headers to make this easier or should we allow with and without and just validate before inserting so we can call the right code?


Code for insert command using C#, SQL, and ASP.NET


I'm having problems getting my code to work.  I have a couple text boxes.  When I hit the button I want it to insert the data from the two text boxes into the SQL database.  Could some show me some C# code that does this from something that actually works?   

read a overlength string in code from a DMX query


hello , when i using  the DMX obtain the rules of mining model J26, then i want to show the rules on interface, but when i excuting code:

               string dmx = "SELECT FLATTENED NODE_DESCRIPTION as rule FROM J26.CONTENT WHERE   NODE_TYPE = 4            and MARGINAL_PROBABILITY>0.5 and node_support>0 ";

                AdomdDataAdapter ada2 = new AdomdDataAdapter(dmx, conn);
                DataTable temTable2 = new DataTable();
                int MaxRow = 8000;
                temTable2.MinimumCapacity = MaxRow;
                 string RTRule = temTable2.Rows[0][0].ToString();

it throws out an error: there is no rows in temTable2.

and RTRule is null .

so ,could

how to access fields on a formview insert template from code behind


I want to access some fields from my formview insertmode.  I am in the code behind and it will not allow me to see them....


any help...


EF 4.1 connection string code first and object context


I have a question about using  an existing sql express(from a web host) with entity framework 4.1) and using an existing database  

Does this map directly using the following method. I posted this question in the msdn site and I really did not get a very good response so I hope someone helps out. my question Is what is the best way to map to an existing database on a web host    

  http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-code-first-walkthrough.aspx here is using a sql  default constructor

http://msdn.microsoft.com/en-us/library/bb896291.aspx you have to pre-configure entity framework here ....

I was wondering is this the way you do it using objectcontext

Public class  Blog context: Db context

public Blogcontext (Db connection connection)


how to insert image into sql server manually (without code)

Can someone please tell me how to insert image into SQL server 2005 manually - without code.

I'm set the field as data type "image" and tried classical copy paste method, but without result.


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