Inserting A Checkbox Value Into Bit Field Sql Server 2000

Dec 17, 2004

Edited by SomeNewKid. Please post code between <code> and </code> tags.








This is probaly the easiest question you've ever read but here goes.





I have a simple checkbox value that i want to insert into the database but whatever i do it does not seem to let me.





Here is my code:





Sub AddSection_Click(Sender As Object, e As EventArgs)


Dim myCommand As SqlCommand


Dim insertCmd As String


' Build a SQL INSERT statement string for all the input-form


' field values.


insertCmd = "insert into Customers values (@SectionName, @SectionLink, @Title, @NewWindow, @LatestNews, @Partners, @Support);"


' Initialize the SqlCommand with the new SQL string.


myCommand = New SqlCommand(insertCmd, myConnection)


' Create new parameters for the SqlCommand object and


' initialize them to the input-form field values.


myCommand.Parameters.Add(New SqlParameter("@SectionName", SqlDbType.nVarChar, 50))


myCommand.Parameters("@SectionName").Value = Section_name.Value





myCommand.Parameters.Add(New SqlParameter("@SectionLink", SqlDbType.nVarChar, 80))


myCommand.Parameters("@SectionLink").Value = Section_link.Value





myCommand.Parameters.Add(New SqlParameter("@Title", SqlDbType.nVarChar, 50))


myCommand.Parameters("@Title").Value = Section_title.Value





If New_window.Checked = false Then


myCommand.Parameters.Add(New SqlParameter("@NewWindow", SqlDbType.bit, 1))


myCommand.Parameters("@NewWindow").Value = 0


else


myCommand.Parameters.Add(New SqlParameter("@NewWindow", SqlDbType.bit, 1))


myCommand.Parameters("@NewWindow").Value = 1


End If





If Latest_news.Checked = false Then


myCommand.Parameters.Add(New SqlParameter("@LatestNews", SqlDbType.bit, 1))


myCommand.Parameters("@LatestNews").Value = 0


else


myCommand.Parameters.Add(New SqlParameter("@LatestNews", SqlDbType.bit, 1))


myCommand.Parameters("@LatestNews").Value = 1


End If





If Partners.Checked = false Then


myCommand.Parameters.Add(New SqlParameter("@Partners", SqlDbType.bit, 1))


myCommand.Parameters("@Partners").Value = 0


else


myCommand.Parameters.Add(New SqlParameter("@Partners", SqlDbType.bit, 1))


myCommand.Parameters("@Partners").Value = 1


End If





If Support.Checked = false Then


myCommand.Parameters.Add(New SqlParameter("@Support", SqlDbType.bit, 1))


myCommand.Parameters("@Support").Value = 0


else


myCommand.Parameters.Add(New SqlParameter("@Support", SqlDbType.bit, 1))


myCommand.Parameters("@Support").Value = 1


End If





myCommand.Connection.Open()


' Test whether the new row can be added and display the


' appropriate message box to the user.


Try


myCommand.ExecuteNonQuery()


Message.InnerHtml = "Record Added<br>" & insertCmd


Catch ex As SqlException


If ex.Number = 2627 Then


Message.InnerHtml = "ERROR: A record already exists with " _


& "the same primary key"


Else


Message.InnerHtml = "ERROR: Could not add record, please " _


& "ensure the fields are correctly filled out"


Message.Style("color") = "red"


End If


End Try





myCommand.Connection.Close()


BindGrid()


End Sub





Any response would be appreciated

View 2 Replies


ADVERTISEMENT

Inserting CheckBox Values Into A Database (MSSQL 2000)

Sep 12, 2005

I have been trying to add values to a database and it keeps failing
i have no idea what i am doing wrong please help the code is asp.net
using vb. I have been having serious trouble passing check boxes in
forms from day one both singularly and dynamically from datagrids
if someone could show me some sample code of how to pass these
sort of values into the component and on to the query in this way
i would very much appreciate it.

Fuzzygoth

the error returned is

Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException:
INSERT statement conflicted with COLUMN FOREIGN KEY constraint
'tblStation_FK00'. The conflict occurred in database 'TealSQL', table
'tblTravelPoint', column 'travelpointID'.
The statement has been terminated.

I have marked the area of the code the error is returned in the colour Violet and with a ##

The code i am using is below


## The aspx page ##

<%@ Page Language="vb" Debug="true" Trace="True"
Inherits="Devotion2Motion.AdminComp"
Src="../CodeBehind/AdminModule.vb"   %>
<!-- Binds the ActivityResortInfo.ascx user control to the page -->
<%@ Register TagPrefix="UserContol" TagName="D2MHeader" Src="../UserControls/Header.ascx" %>
<%@ Register TagPrefix="UserContol" TagName="D2MFooter" Src="../UserControls/Footer.ascx" %>
<%@ Register TagPrefix="UserContol" TagName="TravelPointDD" Src="../UserControls/TravelPointDD.ascx" %>
<script language="vb" runat="server">
   
    Sub Page_Load()
   
        If IsPostback = True Then
       
        Dim aInternational As Integer
       
        Dim Station As String = Request.Form("StationFrm")
        Dim Type As String = Request.Form("TypeFrm")
        Dim Address1 As String = Request.Form("address1Frm")
        Dim Address2 As String = Request.Form("address2Frm")
        Dim City As String = Request.Form("cityFrm")
        Dim International As String = Request.Form("InternationalFrm")
        Dim TravelPoint As Integer = Request.Form("_ctl5:dsTravelPointDD")

            If IsNothing(International) Then
                aInternational = "0"
            Else
                aInternational = "1"
            End If

            Dim AdminTravelPoints As New Devotion2Motion.AdminComp()
            ' Select the country dropdown list
           
AdminTravelPoints.AddStation(Station, Type, Address1, Address2, City,
aInternational, TravelPoint)
               
        End If
       
        Dim ReadResultTable As New Devotion2Motion.AdminComp()
        ' Select the country dropdown list
        dsResultSet.DataSource = ReadResultTable.GetStationtbl()
        dsResultSet.DataBind()
       
    End Sub

</script>


<!-- This UserControl Pulls in the header UserControl and the Div Tag Positions it #css reffrence is TopControl -->
<Div Class="TopControl">
    <UserContol:D2MHeader runat="server"/>
</Div>

<form method="post" action="AdminTravelPoint.aspx" runat="server">
<Div Class="CentreControl">
<table border="0">
<tr>
    <td>
        <asp:Label Text="Station Name: " CssClass="BodyStyle" runat="server"/>
    </td>
    <td>
        <asp:TextBox ID="StationFrm" CssClass="PrimaryGrid" runat="server"/>
    </td>
<tr>
<tr>
    <td>
        <asp:Label Text="Type: " CssClass="BodyStyle" runat="server"/>
    </td>
    <td>
        <asp:TextBox ID="TypeFrm" CssClass="PrimaryGrid" runat="server"/>
    </td>
<tr>
<tr>
    <td>
        <asp:Label Text="Address1: " CssClass="BodyStyle" runat="server"/>
    </td>
    <td>
        <asp:TextBox ID="Address1Frm" CssClass="PrimaryGrid" runat="server"/>
    </td>
<tr>
<tr>
    <td>
        <asp:Label Text="Address2: " CssClass="BodyStyle" runat="server"/>
    </td>
    <td>
        <asp:TextBox ID="Address2Frm" CssClass="PrimaryGrid" runat="server"/>
    </td>
<tr>
<tr>
    <td>
        <asp:Label Text="City: " CssClass="BodyStyle" runat="server"/>
    </td>
    <td>
        <asp:TextBox ID="CityFrm" CssClass="PrimaryGrid" runat="server"/>
    </td>
<tr>
<tr>
    <td>
        <asp:Label Text="International: " CssClass="BodyStyle" runat="server"/>
    </td>
    <td>
        <asp:CheckBox ID="InternationalFrm" CssClass="PrimaryGrid" runat="server"/>
    </td>
<tr>
</tr>
    <td>
        <asp:Label Text="Travel Point: " CssClass="BodyStyle" runat="server"/>
    </td>
    <td>
        <UserContol:TravelPointDD runat="server"/>
    </td>
<tr>
</tr>
    <td>&nbsp;
       
    </td>
    <td>
        <input value="Submit" type="submit">
    </td>
</tr>
</table>
</Div>

<asp:DataGrid ID="dsResultSet" AutoGenerateColumns="False" CssClass="PrimaryGrid" ShowHeader="true" runat="server">
<Columns>
    <asp:BoundColumn DataField="StationID" ReadOnly="true" HeaderText="Station ID"/>
    <asp:BoundColumn DataField="Station" ReadOnly="true" HeaderText="Station"/>
    <asp:BoundColumn DataField="Type" ReadOnly="true" HeaderText="Type"/>
    <asp:BoundColumn DataField="Address1" ReadOnly="true" HeaderText="Address"/>
    <asp:BoundColumn DataField="Address2" ReadOnly="true" HeaderText="&nbsp;"/>
    <asp:BoundColumn DataField="City" ReadOnly="true" HeaderText="City"/>
    <asp:BoundColumn DataField="International" ReadOnly="true" HeaderText="International"/>
    <asp:BoundColumn DataField="TravelPoint" ReadOnly="true" HeaderText="City"/>
</Columns>
</asp:DataGrid>

</form>


<Div Class="CenterControl">
    <UserContol:D2MFooter runat="server"/>
</Div>


##the vb componet that passess to the sql query ##

Public Function AddStation(ByVal Station As String, ByVal Type As
String, ByVal Address1 As String, ByVal Address2 As String, ByVal City
As String, ByVal aInternational As Integer, ByVal TravelPoint As
Integer) As SqlDataReader

            ' Create Instance of Connection and Command Object
            Dim
myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
            Dim
myCommand As New SqlCommand("sp_call_Station_Insert", myConnection)

            ' Mark the Command as a SPROC
            myCommand.CommandType = CommandType.StoredProcedure

            ' Add Parameters to SPROC
            Dim
parameterStation As New SqlParameter("@Station", SqlDbType.NVarChar, 50)
            parameterStation.Value = Station
            myCommand.Parameters.Add(parameterStation)
           
            ' Add Parameters to SPROC
            Dim
parameterType As New SqlParameter("@Type", SqlDbType.NVarChar, 50)
            parameterType.Value = Type
            myCommand.Parameters.Add(parameterType)
           
            ' Add Parameters to SPROC
            Dim
parameterAddress1 As New SqlParameter("@Address1", SqlDbType.NVarChar,
50)
            parameterAddress1.Value = Address1
            myCommand.Parameters.Add(parameterAddress1)

            ' Add Parameters to SPROC
            Dim
parameterAddress2 As New SqlParameter("@Address2", SqlDbType.NVarChar,
50)
            parameterAddress2.Value = Address2
            myCommand.Parameters.Add(parameterAddress2)

            ' Add Parameters to SPROC
            Dim
parameterCity As New SqlParameter("@City", SqlDbType.NVarChar, 50)
            parameterCity.Value = City
            myCommand.Parameters.Add(parameterCity)

            ' Add Parameters to SPROC
            Dim
parameteraInternational As New SqlParameter("@aInternational",
SqlDbType.Int, 4)
            parameteraInternational.Value = aInternational
            myCommand.Parameters.Add(parameteraInternational)

            ' Add Parameters to SPROC
            Dim
parameterTravelPoint As New SqlParameter("@TravelPoint", SqlDbType.Int,
4)
            parameterTravelPoint.Value = TravelPoint
            myCommand.Parameters.Add(parameterTravelPoint)

            ' Execute the command
            myConnection.Open()
           
            ## Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

            ' Return the datareader
            Return result

    End Function


## The sql stored procedure ##

CREATE PROCEDURE [dbo].[sp_call_Station_Insert]
(
@Station As nVarChar(50),
@Type As nVarChar(50),
@address1 As nVarChar(50),
@address2 As nVarChar(50),
@City As nVarChar(50),
@aInternational As nVarChar(50),
@TravelPoint As Int
)
AS


DECLARE @ConVale As nVarChar(50)

SET @ConVale = (SELECT Station FROM tblStation WHERE @Station = Station)

If @ConVale = @Station
   
    BEGIN
        SELECT * FROM tblStation
    END
ELSE
    BEGIN
        insert into tblStation
            (Station, Type, address1, address2, city, International, TravelPoint)
        values (@Station, @Type, @address1, @address2, @City, @aInternational, @TravelPoint)
        SELECT * FROM tblStation

    END
GO

View 1 Replies View Related

Inserting And Retriving Datetime Field In Database MSSQL 2000

Jan 10, 2006

Hi, Assume I have a table name "myTime". This table is simply only have 1 (one) DATETIME field "MyTestTime" (also serve as a primary number).Table MyTime- MyTestTime : SQLTYPE DATETIMETo insert a new row into this field, I simply wrote :SqlCommand sqlCommand = new SqlCommand("insert into MyTime values('2006-01-09')", sqlConnection);
I got the value of "2006-01-09" from a textbox or other relevan control.I realize when I try to use "SELECT * FROM MyTime" statement, MSSQL server 2000 automatically convert my date value from "2006-01-09" to "01/09/2006" (from YYYY-MM-DD to MM/DD/YYYY). I don't know why this one must be converted to MM/DD/YYYY automatically (I believe this behavior is depend on some "setting option" in my MSSQL server - but I don't know which one).The challenge is :In my country, the actual date format is like German Date format (DD-MM-YYY). Well I know this is only "Customization" problem. But how insert datetime value given from sql query to a datetime variable?// Connect to database, make a query, get the datareader result, and bla bla blaDateTime aDateTime = new DateTime;aDateTime = Convert.ToDateTime(myDataReader["PostDate"].ToString());// close connectionMy question isHow can I make sure that aDateTime's day is 09 not 01. How my program know that 09 is day not month. I can't use string.split() method because it's possible that my database setting will change from "mm-dd-yyyy" to "dd-mm-yyyy"thanks

View 4 Replies View Related

Using Checkbox To Save To Bit Field

Jan 30, 2008

Hi All,
I have a database table with a bit field.  In my .aspx page I have a checkbox that is checked by default.  My SqlDataSource is set up like so:
    InsertCommand="INSERT INTO Studies (Study_Name, Study_Status) VALUES (@StudyName, @StudyStatus)">        <InsertParameters>            <asp:ControlParameter ControlID="txtStudyName" Name="StudyName" PropertyName="Text" Type="String"/>            <asp:ControlParameter ControlID="chkboxStudyStatus" Name="StudyStatus" PropertyName="Text" Type="Boolean"/>
I'm getting an error when inserting. 
Error: Cannot insert the value NULL into column 'Study_Status', table 'Studies'; column does not allow nulls. INSERT fails. The statement has been terminated.

View 2 Replies View Related

Checkbox - Using In Update Statement As Bit Field

Jul 24, 2006

hi I have a bit field in sql server represented by a checkbox ... I am updating the database in code ( ie not using formview generated update .. ) the line that is falling over is .Parameters.Add("@archive", SqlDbType.Bit).Value = txtarchive.Checkedit falls over saying failed to convert string parameter to boolean the
value of txtarchive.checked is either true or false - how do i convert
this to 1 or 0 or something that sql is happy with ... thanks

View 2 Replies View Related

Multiple Checkbox Field Width In A Report Parameter.

Oct 30, 2007

Hello,

I have a report where I'm showing a list of users to select.
When previewing the report, the width of the field is automatically set to the largest label in the dropdown list.
But when I change the parameter to have "Multi-Values", then the width is set to a fixed value and a horizontal scrollbar appears.
Does anyone know how to have a "Multi-Values" parameter, but keeping the lasgest width of the labels in the dropdown list ?

Thanks in advance

View 3 Replies View Related

Checkbox Data-bound To A Bit SQL Field Can't Handle NULL Values

Jun 18, 2004

I have a checkbox on my webform that is bound to a bit field in my SQL table. I'm fine as long as I've got the bit field set to 0 or 1, but if the field is NULL, the checkbox throws an exception during the databind.

Is there any way to handle this without removing the data binding and manually setting the value (ie: some way to intercept it before the exception gets thrown and then setting the field value in the dataset)?

Thanks!

View 1 Replies View Related

SQL Server 2012 :: Float Value Converting To Exponential While Inserting To Varchar Field?

Aug 6, 2015

Am converting varchar field to float and summing using group by and next inserting to varchar field(table).

while inserting float value it is converting to exponential ex:1.04177e+006 but if i execute only select statment actual float value will get display ex:1041765.726

My question is why it is converting while inserting ? and how to avoid it.

select query : SUM(CONVERT(float,(rtrim(REPLACE(REPLACE( column1, CHAR(13), ' '), CHAR(10), ' '))))) as AggregateValue

View 4 Replies View Related

How Can I Get Identitiy Field From Database While Inserting New Row In Sql Server 2005 Compact Edition

Aug 2, 2007



How Can I get Identitiy field from database while inserting new row in sql server 2005 compact edition.

Ex:

I am inserting row in a table through SqlQuery ("insert into ....") in which one of the field is of type Identity which generates number automatically. I want that number to pick up that number and used it in child table....


Any solution for it.


View 10 Replies View Related

Help With Inserting Array Contents To SQL Server 2000

Jan 29, 2007

I've been doing this in Access, but cannot find the answer to how to do it with SQL Server.
From a web form, a user can select a number of different dates.  The selected dates are held as text (not DateTime) in an ArrayList.
Clicking the Submit button writes the contents of the form to a database table.
This works for Access:
    insSQL &= "VALUES (@typEvent, @starts, @ends, @starts, @ends, @attend, @title, @room, @department, @contact, @address, @telephone, @email, @telefax, "    For i = 0 to datesArray.Count - 1      insSql &= datesArray.Item(i)    Next i
    insSQL &= "VALUES (@typEvent, @starts, @ends, @starts, @ends, @attend, @title, @room, @department, @contact, @address, @telephone, @email, @telefax, "    For i = 0 to datesArray.Count - 1      insSql &= "#" & datesArray.Item(i) & "#, "    Next i
It doesn't work for SQL Server, and when trying to insert the value "01/29/2007" I get the error message: "The name '#1' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted."
I have also tried the line:
    For i = 0 to datesArray.Count - 1      insSql &= satesArray.Item(i)    Next i
and get: "Incorrect syntax near the keyword 'VALUES'."
I'm not sure where to find the information to correct my error.
Any help would be appreciated.
Tinker
 

View 3 Replies View Related

Problem Inserting Decimal Value Into SQL Server 2000

Aug 19, 2007

In my VS 2005 windows control I am inserting a record into a table using a proc.
One of the fields "Accuracy" should look like this 66.4, but when I isnert it from the proc itlooks like 66.0.  If I bypass my proc and use an inser statement from SQL quey analyzer it look like it should 66.4.
What am I doing wrong in my proc....
 
CREATE PROCEDURE [dbo].[insMyLameProc]
@PlayerName nvarchar(255),@Score int,@Rounds int,@Accuracy decimal,@CorrectPicks int,@IncorrectPicks int
AS
--Insert the new game score--===============================================================================================insert into wmTurnTileScores(PlayerName, Score, Rounds, Accuracy, CorrectPicks, IncorrectPicks)
values (@PlayerName, @Score,  @Rounds, @Accuracy, @CorrectPicks, @IncorrectPicks)--===============================================================================================GO

View 3 Replies View Related

Problem Inserting Data Into SQL Server 2000

Mar 21, 2004

Tryinna insert a new row

This is my code:
Dim myConn As SqlConnection
Dim mycmd As SqlCommand
myConn = New SqlConnection("Initial Catalog=science;" & _
"Data Source=localhost;Integrated Security=SSPI;")
mycmd = New SqlCommand("INSERT into STEP1(firstname) VALUES('Amin')", myConn)
myConn.Open()
mycmd.ExecuteNonQuery()
myConn.Close()

This is the error message I get:
The name 'firstname' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

View 9 Replies View Related

SQL Server 2000 + Inserting Quoted Strings

Jul 27, 2006

Hello,

I am trying to insert quoted strings into a database table, however, I cannot remember how to do so. For instance, I am trying to insert the following values into a SQL table:

My Friend's
"Happy Birthday"

exactly as they are listed. How can I do that in a SQL insert statement?

Thanks,
Crystal

View 1 Replies View Related

Inserting Image Data Type From SQL Server CE To SQL Server 2000.

Oct 23, 2006

Hi All,

I am manually replicating parts of a SQL Server CE database (running windows mobile 5.0) to a centralized SQL Server 2000 database.

My program is throwing an exception whenever I try to insert an image data type into the 2000 server from the PDA. I am using parameterized queries.

Error is as follows:
[error]
System.Data.SqlClient.SqlConnection.OnError()
at
System.Data.SqlClient.SqlInternalConnection.OnError()
at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at
System.Data.SqlClient.TdsParser.Run()
at
System.Data.SqlClient.ExecuteReader()
at
System.Data.SqlClient.ExecuteNonQuery()
at
PDASync.Database.ExecuteIDRemote()
[/error]

The code for my ExecuteIDRemote method works fine for other queries. It also works if I remove the image column from the offending query.

Does anyone have any suggestions? Thanks.

View 1 Replies View Related

Inserting Mysql Dump File To SQL Server 2000

Apr 14, 2004

Hi,
I would preciated if some could help me with this problem.
My have used Mysql database and now i have to change my database to sql server.
I have made a dump file from mysql db and i would like to insert that dumb file to sql server.
Have any idea how it is possible?

cheers,
inkku

View 1 Replies View Related

Inserting A File Into Nvarbinary Column In SQL Server 2000

Apr 19, 2006

Hi Folks,

I was wondering if someone could give some advice on the best way to insert a file to nvarbinary column.

Currently, I have a table like so:

FileID (bigInt, 8)
Name (nvarchar, 255)
File (nvarbinary, 8000)

I would like to insert a file into the file column.

The problem is reading the file from the filesystem into the database.Could anyone give me some advice on the best way to do this?

Many thanks in advance,

Morris

View 1 Replies View Related

Inserting Data Having Japanese Characters(Kanji) In SQL Server 2000

Oct 15, 2007



Hi All,
I am working on SQL Server 2000 ver 7.0. The Collation set for my Database Server is Latin.
I want some way by which i can insert Japanese Characters in Database. Is it related to change the Collation or any other encoding format of database.
Suppose the table 'Person' has fields id, Name, city
If i enter name in a japanese characters, then while storing it does not recongnises this format.

insert into person values(8,'満員','osaka')

id name city
8 ?? osaka
At the place of name '??' is displayed.

Please sugggest me a solution for this.


Thanks in Advance Manohar

View 11 Replies View Related

Inserting Image Data Fails With Connection Broken (SQL Server 2000 And SQL Native Client)

May 28, 2008

Dear all,

we have tables with many image columns. We fill these image columns via ODBC and SQLPutData as described in MSDN etc (using SQL_LEN_DATA_AT_EXEC(...), calling SQLParamData and sending the data in chunks of 4096 bytes when receiving SQL_NEED_DATA).

The SQLPutData call fails under the following conditions with sqlstate 08S01

- The database resides on SQL Server 2000
- The driver is SQL Native Client
- The table consists e.g. of one Identity column (key column) and nine image columns
- The data to be inserted are nine blocks of data with the following byte size:


1: 6781262
2: 119454

3: 269
4: 7611

5: 120054

6: 269

7: 8172

8: 120054

9: 269
The content of the data does not matter, (it happens also if only zero bytes are written), nor does the data origin (file or memory).

All data blocks including no 7 are inserted. If the first chunk of data block 8 should be written with SQLPutData the function fails and the connection is broken. There are errors such as "broken pipe" or "I/O error" depending on the used network protocol.

If data no 7 consists of 8173 bytes instead of 8172 all works again.
(Changing the 4096 chunk size length does not help)

Has anybody encountered this or a similar phenomenon?

Thank you

Eartha

View 7 Replies View Related

Working In VB.Net 2005 Inserting NULL Into A Field In Microsoft SQL Server 2005

Feb 2, 2007

I am update/inserting records threw a web form in vb.net. I need to insert 'NULL'  into my microsoft sql server database.  I am not talking about the below line of code where website is the name of my paramater.  If i do that it will just place a blank into that field in the database.  If i dont enter anything into that textbox I want it to to say NULL in that field. So if I go into the actual table in the SQL Server Management Studio and look at the website field of the recored I just added or updated and did not type anything into the web site textbox it needs to say NULL.  I also tried the second line of code but that places a single quote in front and behind NULL. So the field will have the value 'NULL'.
website.value = txtwebsite.text.tostirng
 if txtwebsite.text ="" then
   website.value ="NULL"
end if
The reason why I need the NULL there is because I bind the website filed to a hyperlink template in a gridview.  The actual text of the hyperlink is bound to PAYER which is a name of a insurance payer but the navigateto is bound to the website field.  If i do not enter any data into the website field and it stays as NULL, then when my gridview is loaded, payers that dont have a website will not be underlined and user wont have the option to click on them since there is no value for the navigateto.  But if i use my form to update/add a payer and leave the website textbox blank in puts a blank into that field in my database and when it loads that new row into the gridview the PAYER is underlined and u can click on it but it will just take u to the web site is unavailable page.  So is there anyway to actaull have NULL placed into a filed and not just blank space

View 3 Replies View Related

Checkbox Value In Table On Sql-server

Mar 7, 2008

Hello
I need to make a webpage that stores the name, email, ... from the user into a database.  The user also checks several checkboxes to register for some items.  That last one gives me some trouble.  Inside my code the checkbox-value is stored into a Boolean (true of false).  On the sql-server I declared my field as a Bit (0 or 1). 

 1 public string Input_inschrijving(cls_inschrijving nieuwe_inschrijving) {
2
3
4
5 inschrijving_cn = new SqlConnection("Data Source=serverIp;Persist Security Info=True;User ID=DBname;Password=mypasword");
6
7
8
9 string stUser = "INSERT INTO tbl_inschrijving (naam, voornaam, straat, nr, postcode, woonplaats, telefoon, email, functie, organisatie, ostraat, onr, opostcode, owoonplaats, otelefoon, oemail, ws1, ws2, ws3, ws4, ws5, ws6, ws7, ws8, ws9, ws10, ws11, ws12) VALUES ('" + m_naam + "', '" + m_voornaam + "', '" + m_straat + "', '" + m_nr + "', '" + m_postcode + "', '" + m_woonplaats + "', '" + m_telefoon + "', '" + m_email + "', '" + m_functie + "', '" + m_organisatie + "', '" + m_ostraat + "', '" + m_onr + "', '" + m_opostcode + "', '" + m_owoonplaats + "', '" + m_otelefoon + "', '" + m_oemail + "', " + m_ws1 + " , " + m_ws2 + " , " + m_ws3 + " , " + m_ws4 + " , " + m_ws5 + " , " + m_ws6 + " , " + m_ws7 + " , " + m_ws8 + " , " + m_ws9 + " , " + m_ws10 + " , " + m_ws11 + " , " + m_ws12 + ")";
10
11
12
13 cm = new SqlCommand(stUser, inschrijving_cn);
14
15
16
17 try
18
19 {
20
21 inschrijving_cn.Open();
22
23 dr = cm.ExecuteReader();
24
25 dr.Close();
26
27 inschrijving_cn.Close();
28
29 return "Your registration was succesfull!";
30
31
32
33 }
34
35 catch(SqlException sx) {
36
37 return "Error!" + sx.Message;
38
39 }
40
41 }
42

Inside the table tbl_inschrijving on the SQL-server, i declared the checkbox values ws1, ws2, ws3, ... to a bit with length 1 (nulls allowed)How can I store the boolean-value into my table?  I tried to change several declarations (int, char, varchar...) nothing works.

View 3 Replies View Related

No SQL Server Reporting Services Checkbox?

Mar 2, 2005

Am I correct in finding that there's no checkbox in SQL Server Reporting Services? What other way do you have to display a bit field other than 0-1 ??

View 1 Replies View Related

Encrypting A Field In SQL Server 2000

Jul 20, 2006

Hi,
I have a SSN field that I need to encrypt.  Only persons who wants to get information about a user should be able to decrypt that field.  What is the best way to encrypt and decrypt the ssn field?  Thanks

View 2 Replies View Related

Formula Field In SQL Server 2000

Oct 20, 2004

Does anyone know how to use Formula Field in SQL Server 2000. I have googled a lot, but haven't been able to find out how to use it..

Thx

View 2 Replies View Related

How To Copy The Value Of One Field Into Another Using SQL Server 2000

Oct 20, 2006

I am a little embarrased to be asking this question because I know that the answer must be simple but I am still a nube at SQL. I am stuck with a simple query that copies one field of data into another. Below is the script that I am trying to execute.

UPDATE table
SET field2 = field1

I get an error from SQL Server that says that the String or binary data would be truncated. I am assuming that the SQL server is trying to concatenate all the value of field1 into field2. All I am trying to do is copy the values of one field into another for each and every row in the table. Thanks in advance.

View 3 Replies View Related

SQL Server 2000 Filling A Key Field

Jul 20, 2005

I have a table that has a int field that contains unique nubers.if I need to insert 4000 or so new records into this table using a SQLcommand how would I be able to fill this field with the next availablenumber?This will be a manual procedure done maybe once a year so the nextnumber will be known ahaed of time. but the insert command need toincrement this number by one everytime it puts a new row in.

View 2 Replies View Related

Help Inserting Into Datetime Field

Feb 7, 2007

I keep getting the following error message but I don't see what's wrong with my code

Server Error in '/Admin' Application.


Arithmetic overflow error converting expression to data type datetime.The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Arithmetic overflow error converting expression to data type datetime.The statement has been terminated.Source Error:



Line 147:cmdSql.Parameters.Add("@event_active","1")
Line 148:
Line 149:cmdSql.ExecuteNonQuery()
Line 150:
Line 151:pnlForm.Visible = FalseSource File: c:hostingwebhost4lifememberNYACOAadmincalendar.aspx    Line: 149 Stack Trace:



[SqlException (0x80131904): Arithmetic overflow error converting expression to data type datetime.
The statement has been terminated.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857466
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +735078
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +149
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +415
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135
ASP.calendar_aspx.SubmitForm(Object s, EventArgs E) in c:hostingwebhost4lifememberNYACOAadmincalendar.aspx:149
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102



Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
  1 <%@ Register TagPrefix="cc1" Namespace="ManyMonkeys.Web.HtmlEditorLibrary.Controls" Assembly="HtmlEditorLibrary" %>
2 <%@ Page Language="VB" masterpagefile="nyacoaadmin.master" debug="true" %>
3 <%@ mastertype virtualpath="nyacoaadmin.master" %>
4 <%@ import Namespace="System" %>
5 <%@ import Namespace="System.Data" %>
6 <%@ import Namespace="System.Data.SqlClient" %>
7 <script runat="server">
8
9 Dim Connection As SqlConnection
10 Dim Sql As String
11 Dim cmdSql As SqlCommand
12 Dim dtr As SqlDataReader
13
14 Sub Page_Load
15
16 Connection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
17 Connection.Open()
18
19 If Not isPostback then
20
21 Sql = "SELECT chapter_id, chapter_name FROM chapter ORDER BY chapter_id"
22 cmdSql = New SqlCommand (Sql, Connection)
23 dtr = cmdSql.ExecuteReader()
24
25 ddlChapter.DataSource = dtr
26 ddlChapter.DataTextField = "chapter_name"
27 ddlChapter.DataValueField = "chapter_name"
28 ddlChapter.DataBind()
29
30 dtr.Close
31
32 ddlChapter.Items.Insert(0, New ListItem(" ", ""))
33
34 Call ShowList()
35
36 End If
37
38 End Sub
39
40 Sub Page_Unload
41
42 'Connection.Close()
43
44 End Sub
45
46 Sub ShowList()
47
48 Sql = "SELECT event_id, event_name, event_date, chapter_name FROM event WHERE event_active = '1' ORDER BY event_id"
49 cmdSql = New SqlCommand(sql, Connection)
50 dtr = cmdSql.ExecuteReader()
51
52 dgrdList.DataSource = dtr
53 dgrdList.DataBind()
54 dtr.Close()
55
56 pnlList.Visible = True
57
58 End Sub
59
60 Sub dgrdList_ItemCommand(s As Object, E As DataGridCommandEventArgs)
61
62 If e.CommandName = "edit" then
63 Call EditForm(dgrdList.DataKeys(e.Item.ItemIndex))
64 Else If e.CommandName = "delete" then
65 Call ConfirmDelete(dgrdList.DataKeys(e.Item.ItemIndex))
66 End If
67
68 End Sub
69
70 Sub ConfirmDelete(idVal As Integer)
71
72 pnlList.Visible = False
73 pnlConfirmDelete.Visible = True
74
75 sql = "SELECT event_name FROM event WHERE event_id = " & idVal
76 cmdSql = New SqlCommand(sql, connection)
77 litDelete.Text = cmdSql.ExecuteScalar()
78
79 ViewState("idVal") = idVal
80
81 End Sub
82
83 Sub DeleteForm (s As Object, E As Eventargs)
84
85 sql = "UPDATE event SET event_active = '0' WHERE event_id = " & ViewState("idVal")
86 cmdSql = New SqlCommand(sql, connection)
87 cmdSql.ExecuteNonQuery()
88
89 pnlList.Visible = True
90 pnlConfirmDelete.Visible = False
91
92 Call ShowList()
93
94 End Sub
95
96 Sub ShowCalendar(s As Object, E As ImageClickEventargs)
97
98 pnlEventDate.Visible = True
99
100 End Sub
101
102 Sub UpdateDate (s As Object, E As Eventargs)
103
104 pnlEventDate.Visible = False
105 txtEventDate.text=eventCalendar.SelectedDate.ToShortDateString()
106
107 End Sub
108
109 Sub SubmitForm (s As Object, E As Eventargs)
110
111 If ViewState("submitType") = "edit" then
112 sql = "UPDATE event SET event_name=@event_name, event_date=@event_date, chapter_name=@chapter_name, event_description=@event_description, event_last_updated_by=@event_last_updated_by, event_active=@event_active WHERE event_id = " & ViewState("idVal")
113 Else
114 sql = "INSERT INTO event (event_name, event_date, chapter_name, event_description, event_added_by, event_last_updated_by, event_active) VALUES (@event_name, @event_date, @chapter_name, @event_description, @event_added_by, @event_last_updated_by, @event_active)"
115 End If
116
117 cmdSql = New SqlCommand(sql, Connection)
118
119 If Len(txtEventName.Text) = 0 then
120 cmdSql.Parameters.Add("@event_name",DbNull.Value)
121 Else
122 cmdSql.Parameters.Add("@event_name",txtEventName.Text)
123 End If
124
125 If Len(txtEventDate.Text) = 0 then
126 cmdSql.Parameters.Add("@event_date",DbNull.Value)
127 Else
128 cmdSql.Parameters.Add("@event_date",txtEventDate.Text & " " & ddlEventHour.SelectedValue & ":" & ddlEventMinute.SelectedValue & " " & ddlEventAMPM.SelectedValue)
129 End If
130
131 If Len(ddlChapter.SelectedValue) = 0 then
132 cmdSql.Parameters.Add("@chapter_name",DbNull.Value)
133 Else
134 cmdSql.Parameters.Add("@chapter_name",ddlChapter.SelectedValue)
135 End If
136
137 If Len(txtEventDescription.Text) = 0 then
138 cmdSql.Parameters.Add("@event_description",DbNull.Value)
139 Else
140 cmdSql.Parameters.Add("@event_description",txtEventDescription.Text)
141 End If
142
143 cmdSql.Parameters.Add("@event_added_by",session("admin_username"))
144
145 cmdSql.Parameters.Add("@event_last_updated_by",session("admin_username"))
146
147 cmdSql.Parameters.Add("@event_active","1")
148
149 cmdSql.ExecuteNonQuery()
150
151 pnlForm.Visible = False
152 pnlList.Visible = True
153
154 Call ShowList()
155
156 End Sub
157
158 Sub AddForm(s As Object, E As Eventargs)
159
160 pnlForm.Visible = True
161 pnlList.Visible = False
162
163 txtEventName.Text = ""
164 txtEventDate.Text = ""
165 ddlChapter.ClearSelection()
166 txtEventDescription.Text = ""
167
168 ViewState("submitType") = "add"
169
170 End Sub
171
172 Sub EditForm (idVal As Integer)
173
174 pnlList.Visible = False
175 pnlForm.Visible = True
176
177 sql = "SELECT * FROM event WHERE event_id = " & idVal
178 cmdSql = New SqlCommand(sql, connection)
179 dtr = cmdSql.ExecuteReader()
180
181 If dtr.Read() then
182
183 txtEventName.Text = dtr("event_name") & ""
184 txtEventDate.Text = dtr("event_date") & ""
185 txtEventDescription.Text = dtr("event_description") & ""
186 ddlChapter.ClearSelection()
187 Try
188 ddlChapter.Items.FindByValue(dtr("chapter_name")).Selected = True
189 Catch Ex As Exception
190 End Try
191
192 End If
193
194 dtr.Close()
195
196 ViewState("submitType") = "edit"
197 ViewState("idVal") = idVal
198
199 End Sub
200
201 Sub DeleteCancel (s As Object, E As Eventargs)
202
203 pnlConfirmDelete.Visible = False
204 pnlList.Visible = True
205
206 End Sub
207
208 </script>
209
210 <asp:Content contentplaceholderid="cplhMainContent" runat="server">
211
212 <asp:Panel runat="server" id="pnlList" Visible="False">
213
214 <asp:DataGrid runat="server" id="dgrdList" AutoGenerateColumns="False" CellPadding="3" CellSpacing="0" width="550" Border="0" DataKeyField="event_id" onItemCommand="dgrdList_ItemCommand">
215 <HeaderStyle BackColor="#CDAD00" Font-Names="Tahoma,Arial,Helvetica,sans-serif" Font-Bold="true" Font-Size="10pt" HorizontalAlign="center" ForeColor="white" />
216 <ItemStyle BackColor="white" Font-Names="Tahoma,Arial,Helvetica,sans-serif" Font-Size="10pt" ForeColor="black" VerticalAlign="top" />
217 <AlternatingItemStyle BackColor="#dcdcdc" Font-Names="Tahoma,Arial,Helvetica,sans-serif" Font-Size="10pt" ForeColor="black" VerticalAlign="top" />
218 <Columns>
219 <asp:ButtonColumn Text="Edit" ButtonType="PushButton" CommandName="edit" />
220 <asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="delete" />
221 <asp:BoundColumn DataField="event_name" HeaderText="Event Name" />
222 <asp:BoundColumn DataField="event_date" HeaderText="Date" />
223 <asp:BoundColumn DataField="chapter_name" HeaderText="Sponsoring Chapter" />
224 </Columns>
225 </asp:DataGrid>
226
227 <asp:Button runat="server" Text="Add New Event" onClick="AddForm"></asp:Button>
228
229 </asp:Panel>
230
231 <asp:Panel runat="server" id="pnlForm" Visible="False">
232
233 Name of Event: <asp:TextBox id="txtEventName" runat="server"></asp:TextBox>
234 <br />Chapter: <asp:DropDownList id="ddlChapter" runat="server" AutoPostBack="False" />
235 <br />Date: <asp:TextBox id="txtEventDate" runat="server" ReadOnly="true" BackColor="Gray"></asp:TextBox> <asp:ImageButton id="CalButton" runat="server" OnClick="ShowCalendar" ImageUrl="images/cal.gif" />
236 <br /><asp:Panel runat="server" id="pnlEventDate" Visible="False">
237 <asp:Calendar id="eventCalendar" runat="server" FirstDayOfWeek="Sunday" Font-Names="Tahoma" Font-Size="8pt" OnSelectionChanged="UpdateDate">
238 <SelectedDayStyle BackColor="#EC9900" Font-Bold="True" />
239 <TodayDayStyle BackColor="#FFC0C0" />
240 <SelectorStyle Font-Names="Tahoma" Font-Size="8pt" />
241 <DayStyle Font-Names="Tahoma" Font-Size="8pt" />
242 <WeekendDayStyle BackColor="#E0E0E0" />
243 <OtherMonthDayStyle ForeColor="Silver" />
244 <DayHeaderStyle BackColor="#334B79" Font-Names="Tahoma" Font-Size="8pt" ForeColor="White" />
245 <TitleStyle BackColor="#CCCCFF" Font-Bold="True" Font-Names="Tahoma" Font-Size="10pt" />
246 </asp:Calendar>
247 <br />
248 </asp:Panel>
249 Time: <asp:DropDownList ID="ddlEventHour" runat="server" >
250 <asp:ListItem Text="12" Value="12" Selected="true"/>
251 <asp:ListItem Text="1" Value="1" />
252 <asp:ListItem Text="2" Value="2" />
253 <asp:ListItem Text="3" Value="3" />
254 <asp:ListItem Text="4" Value="4" />
255 <asp:ListItem Text="5" Value="5" />
256 <asp:ListItem Text="6" Value="6" />
257 <asp:ListItem Text="7" Value="7" />
258 <asp:ListItem Text="8" Value="8" />
259 <asp:ListItem Text="9" Value="9" />
260 <asp:ListItem Text="10" Value="10" />
261 <asp:ListItem Text="11" Value="11" />
262 </asp:DropDownList>
263 :
264 <asp:DropDownList ID="ddlEventMinute" runat="server">
265 <asp:ListItem Text="00" Value="00" Selected="true" />
266 <asp:ListItem Text="15" Value="15" />
267 <asp:ListItem Text="30" Value="30" />
268 <asp:ListItem Text="45" Value="45" />
269 </asp:DropDownList>
270 <asp:DropDownList ID="ddlEventAMPM" runat="server">
271 <asp:ListItem Text="AM" Value="AM" />
272 <asp:ListItem Text="PM" Value="PM" Selected="true" />
273 </asp:DropDownList>
274 <br /><br />
275 Content:
276 <br /><cc1:HtmlEditor id="txtEventDescription" runat="server" Height="300px" Width="575px"></cc1:HtmlEditor>
277 <br /><br />
278 <asp:Button onclick="SubmitForm" runat="server" Text="Submit"></asp:Button>
279
280 </asp:Panel>
281
282 <asp:Panel runat="server" id="pnlConfirmDelete" Visible="False">
283
284 Are you sure you wish to delete <asp:Literal runat="server" id="litDelete"></asp:Literal>?
285 <br /><br />
286 <asp:Button runat="server" Text="Yes - DELETE" onClick="DeleteForm"></asp:Button>&nbsp;<asp:Button runat="server" Text="No - GO BACK" onClick="DeleteCancel"></asp:Button>
287
288 </asp:Panel>
289
290 </asp:Content>
 

View 4 Replies View Related

Inserting Symbols In Field

Jul 29, 2007

Hi All,I am trying to insert symbols in a field of a table. I am using the datatype nvarchar for the field.However when i tried to insert a statement with the symbol pi, it comes out as following:(A) 100? cm2    (B) 140? cm2    (C) 200? cm2All the pi symbol are converted to ?.Can ne 1 tell me how i can store such strings in the field.Thanks

View 1 Replies View Related

Adding A Field And Inserting A Value Into It.

Apr 24, 2002

how do i add a new field and insert a value into it?

I'm importing data from another table into a new one, but my source table has a char field and the target filed is (int) can I add a new field to the source file and add a value to it? and how?
I have in my source table a field call companyName that contains text and the target table has a companyId which is an INT.
If I create a field call companyId and add a value of '1' depending on the value of CompanyName...
This is what i want ot do
if CompanyName = LA then insert 1 into new filed companyID
How can I do that? I have to do this for 100 or more tables. Can I write a script that will do that for me?
does it make sence?

View 2 Replies View Related

Inserting Into Varbinary Field

Apr 21, 2008

Hello,

I'm trying to insert a string expression into a varbinary field. I've tried it several ways, but the data does not seem to get inserted.

I map DT_STR field ("T") with varbinary field in destination table and the package executes properly, but when I see the data that it has been loaded I only see empty values (0x).

I have also tried other approaches, like converting to DT_BYTES during SSIS flow, but I always get the same result.

Any idea of how to achieve this?

View 1 Replies View Related

INSERTING Into IDENTITY Field

Nov 15, 2006

I have a table with the following schema:
CREATE TABLE [itis].[wrk_taxon_authors] (
[wb_taxon_author_id] [int] NOT NULL ,
[taxon_author_id] [int] IDENTITY (1, 1) NOT NULL ,
[taxon_author] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[kingdom_id] [smallint] NOT NULL
) ON [PRIMARY]
GO

I am trying to insert the following data (as you can see fields are seperated with the | ):

19||Flores-Villela and Sánchez-H., 2003|5|
20||Wiegmann, 1828|5|
16|17482|Gray, 1838|5|
17|9823|(Wiegmann, 1828)|5|
I get the following error:Server: Msg 4869, Level 16, State 1, Line 1
Bulk Insert failed. Unexpected NULL value in data file row 1, column 2. Destination column (taxon_author_id) is defined NOT NULL.
Server: Msg 4869, Level 16, State 1, Line 1
Bulk Insert failed. Unexpected NULL value in data file row 2, column 2. Destination column (taxon_author_id) is defined NOT NULL.

Since I have defined column 2 as an identity column, I don't understand why SQL Query analyzer is upset when I do not have a value in that field. To me, I would think it would auto-insert an integer (starting at seed 1 and incrementing by 1), but it doesn't. Could someone tell me what I'm doing wrong?

View 7 Replies View Related

Inserting Symbols In Field

Jul 30, 2007

Hi All,
I am trying to insert symbols in a field of a table.

I am using the datatype nvarchar for the field.
However when i tried to insert a statement with the symbol pi, it comes out as following:
(A) 100? cm2 (B) 140? cm2 (C) 200? cm2

All the pi symbol are converted to ?.

Can ne 1 tell me how i can store such strings in the field.

Thanks

View 3 Replies View Related

Sum Of Time Field In SQL Server 2000 - Very Urgent

Feb 13, 2007

Hello all. I have a nvarchar field in the format dd:hh:mm:ss I need to get a sum of these fields in the same format. So for example if the values are 01:23:00:00 and 00:01:00:00 then the sum of these fields should be 02:00:00:00. Can someone help me? Thanks.

View 12 Replies View Related

Updating Varchar Field In SQL Server 2000

Oct 4, 2004

I would like to update a varchar field with an update statement that appends information to what is currently stored in the field, for example in the Statement field I may currently have a name (Mark) and I want to add a unique identifier to the end of the name so that it may look like, Markq1572, is there a way to do this in an update statement?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved