|
My code is
public void Insert()
{
string query =
"INSERT INTO WordTable (Word_ID,Word,Help) " +
"VALUES (@Word_ID,@Word,@Help)";
SqlConnection conn = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.Add(new SqlParameter("@Word_ID",this.Word_ID));
cmd.Parameters.Add(new SqlParameter ("@Word",this.word));
cmd.Parameters.Add(new SqlParameter ("@Help",this.Help));
conn.Open();
cmd.ExecuteScalar();
}
And the exception is
System.Data.SqlClient.SqlException was unhandled by user code
Message="String or binary data would be truncated.\r\nThe statement has been terminated."
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=8152
Procedure=""
Server="\\\\.\\pipe\\F52FA45D-C426-4C\\tsql\\query"
State=13
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteScalar()
at SQLWord.Insert() in e:\asp.net\hangaro\App_Code\SQLWord.cs:line 48
at WordList.AddWord(SQLWord w) in e:\asp.net\hangaro\App_Code\WordList.cs:line 52
at Add_Word.WriteToSQL() in e:\asp.net\hangaro\Add_Word.aspx.cs:line 60
at Add_Word.Add_Click(Object sender, EventArgs e) in e:\asp.net\hangaro\Add_Word.aspx.cs:line 36
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
I have checked the values of
this.Word_ID etc...
What shall I do ?
Apurv
|
|
|
|
|
Try executenonquery instead of executescalar.
scalar is for a select statement, it returns the first value of the first row.
I didn't get any requirements for the signature
|
|
|
|
|
I am trying to change a LinkButton to disabled/enabled:
LinkButton newNext = (LinkButton)DataList1.FindControl("NextHyperLink");
newNext.Enabled = !pdDataSource.IsLastPage;
this will not work.. it returns that newNext is null...
The linkbuttons are in the HeadTemplate of the DataList1??
|
|
|
|
|
Problem is seems like where you are calling Find Control.
Datalist contains more that one items so you will need to provide specific item.
Can post here code that in which you are calling ?
Parwej Ahamad
R & D: REST services with WCF
|
|
|
|
|
In which event you are trying to access?
If page load i think you cannot...
Try by accessing in the ItemDataBound event... by using e.Item.FindControl
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
The problem was is I was trying to access a LinkButton that was in a DataList and that DataList was in another DataList... (one datalist was in the Headertemplate of another datalist)
Still wonder how to do that though??
|
|
|
|
|
for(int i=0;i<datalist1.items.count;i++)>
{
LinkButton newNext = (LinkButton)DataList1.Items[i].FindControl("NextHyperLink");
}
now u can find the value of LinkButton Control , may b this hyelps you .
|
|
|
|
|
Hi all
I have a text box, which will take input from user in hr:min:sec format.
I would like to verify:
1. User enters the in correct format,
2. I would like to verify of the values are correct, e.g. for hrs < 24, for mins it should be less than 60 and simillarly for sec should be less than 60.
or is there any way, that I can set the text box to take user input as hrs:min:sec format. pls guide me. thanks
|
|
|
|
|
Have you looked at the validation controls that are available?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Thanks for reply. I have regular expression validator, but wanted to have the regular expression to check user input in HH:MM:SS format.
I am using, regular expression
^([0-1][0-9]|2[0-3]) 0-5][0-9]) 0-5][0-9])$
|
|
|
|
|
Have you looked at Expresso, here at CP? It is a really great tool for building/testing regular expressions.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Thanks for the information.
I have following regular expression to check HH:MM:SS format of the text box.
^([0-1]?[0-9]|2[0-3]):([0-5]?[0-9]):([0-5]?[0-9])$
I would like to give the flexibility to the user to enter the data in MM:SS format too. I was trying to modify the above regular expression to validate for the MM:SS format too. but didnt get the success.
can anyone please help me to build the regular expression to allow user to enter data in HH:MM:SS and MM:SS format too.
Thanks a lot.
|
|
|
|
|
Using Visual Studio 2005, when I edit a FormView template it is not presented in WYSIWYG mode, but is reformatted to about half-column size. Is there a trick to being able to edit a template as it will actually look? It looks correct when not in template editing mode.
|
|
|
|
|
VS 2005? Do you use C#, VB, ASP.NET, J#?
Could you be more specific?
|
|
|
|
|
Sorry: C#, VS 2005. When I go into template editing mode the templates are only about half the width of how they display when in non-edit mode. This makes it very hard to get the templates right. The same thing happens with VS 2008.
|
|
|
|
|
can't you use a property like ItemStyleWidth or ControlStyleWidth
|
|
|
|
|
The WIdth property of the FormView conrol is set to 100%. The templates (Edit, Insert, Item, etc) do not have a property sheet that I can find.
The templates display correctly when youo are not in template editing mode, but when you go into template editing mode the width of the Formview shrinks by about 50%, even though the Width property has not changed.
|
|
|
|
|
You might have code that looks like below?
<asp:FormView ID="FormView1" runat="server" DataKeyNames="au_id" DataSourceID="AuthorsSource">
<EditItemTemplate>
au_id: <asp:Label ID="au_idLabel1" runat="server" Text='<%# Eval("au_id") %>'/><br />
au_lname: <asp:TextBox ID="au_lnameTextBox" runat="server" Text='<%# Bind("au_lname") %>'/><br />
au_fname: <asp:TextBox ID="au_fnameTextBox" runat="server" Text='<%# Bind("au_fname") %>'/><br />
phone: <asp:TextBox ID="phoneTextBox" runat="server" Text='<%# Bind("phone") %>'/><br />
address: <asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>'/><br />
city: <asp:TextBox ID="cityTextBox" runat="server" Text='<%# Bind("city") %>'/><br />
state: <asp:TextBox ID="stateTextBox" runat="server" Text='<%# Bind("state") %>'/><br />
zip: <asp:TextBox ID="zipTextBox" runat="server" Text='<%# Bind("zip") %>'/><br />
contract: <asp:CheckBox ID="contractCheckBox" runat="server" Checked='<%# Bind("contract") %>' /><br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
au_id: <asp:TextBox ID="au_idTextBox" runat="server" Text='<%# Bind("au_id") %>'/><br />
au_lname: <asp:TextBox ID="au_lnameTextBox" runat="server" Text='<%# Bind("au_lname") %>'/><br />
au_fname: <asp:TextBox ID="au_fnameTextBox" runat="server" Text='<%# Bind("au_fname") %>'/><br />
phone: <asp:TextBox ID="phoneTextBox" runat="server" Text='<%# Bind("phone") %>'/><br />
address: <asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>'/><br />
city: <asp:TextBox ID="cityTextBox" runat="server" Text='<%# Bind("city") %>'/><br />
state: <asp:TextBox ID="stateTextBox" runat="server" Text='<%# Bind("state") %>'/><br />
zip: <asp:TextBox ID="zipTextBox" runat="server" Text='<%# Bind("zip") %>'/><br />
contract: <asp:CheckBox ID="contractCheckBox" runat="server" Checked='<%# Bind("contract") %>' /><br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
au_id: <asp:Label ID="au_idLabel" runat="server" Text='<%# Eval("au_id") %>'/><br />
au_lname: <asp:Label ID="au_lnameLabel" runat="server" Text='<%# Bind("au_lname") %>'/><br />
au_fname: <asp:Label ID="au_fnameLabel" runat="server" Text='<%# Bind("au_fname") %>'/><br />
phone: <asp:Label ID="phoneLabel" runat="server" Text='<%# Bind("phone") %>'/><br />
address: <asp:Label ID="addressLabel" runat="server" Text='<%# Bind("address") %>'/><br />
city: <asp:Label ID="cityLabel" runat="server" Text='<%# Bind("city") %>'/><br />
state: <asp:Label ID="stateLabel" runat="server" Text='<%# Bind("state") %>'/><br />
zip: <asp:Label ID="zipLabel" runat="server" Text='<%# Bind("zip") %>'/><br />
contract: <asp:CheckBox ID="contractLabel" runat="server" Checked='<%# Bind("contract") %>'
Enabled="false" /><br />
</ItemTemplate>
</asp:FormView>
Each control, like Label or Checkbox have WIDTH properties. What changes for you if you set these ?
|
|
|
|
|
Yes the code is similar but the data is from a datasource and there is no Item template. Some of the controls have width properties set. The width properties do not seem to take effect in template editing mode but when not in template editing mode they are fine. The width of the item template is set to 100%, as is the width of the FormView. I have a table wrapping the contents of each template, and the table width is set to 100%. If I change the width of the table to something like 500px, the template editing mode expands to hold it. But I am trying not to use fixed width tables. When not in template editing mode all the widths are correctly displayed as 100%. They are only squeezed up in template editing mode and only if the widths are set to a percentage.
|
|
|
|
|
LOOKS like you have found a feature in .NET.
Is a GridView not a suitable component for this?
|
|
|
|
|
Oh, great
No, a gridview does not work for this...the formatting needs to be specific.
As a workaround I am setting all the table widths that enclose the templates to fixed widths, and will put them back to 100% before testing.
|
|
|
|
|
Hi All,
I am referring to a WSDL file in my web service application to access a web service. This wsdl has a complex type as follows:
<br />
<xsd:complexType name="PersonalData"><br />
<br />
<xsd:sequence><br />
<br />
<xsd:element name="dateofbirth" type="xsd:date" /><br />
<br />
</xsd:sequence><br />
<br />
</xsd:complexType><br />
<br />
The reference name is PersonalDataWS
I created an object of this web service and assigning some date to the dateofbirth element as follows
objPersonalDataWS.dateofbirth = Convert.ToDateTime("07/07/2008 14:10:00");
The problem is that when the dateofbirth is serialized as XML, only the date part is shown not the time part. Did anyone face this problem?
Is it because the WSDL defines xsd:date and not xsd:dateTime ?
I was reading about the date data type here http://www.w3schools.com/Schema/schema_dtypes_date.asp
but here I see data type xs:dateTime and not xsd:dateTime. Is there any difference?
any help will be greatly appriciated.
S/W Engineer
Akebono Soft Technologies
aleem_abdul@akebonosoft.com.
|
|
|
|
|
Try using the Ignore HTML tags in this message (good for code snippets) checkbox at the bottom to make your code more readable
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I have a FormView control that will either enter or update one (and only) record in a datasource. I need to set the FormView mode based on whether there is a record in the datasource. I know how to switch modes by reading the datasource myself, but is there a way to get the FormView to do it automatically? Or is there a way to get FormView to allow an Empty Template to update the database? It doesn't seem the Empty template will bind to a datasoource the way the Edit template does.
|
|
|
|
|
how to save multiple values into single session using hash key concept
thanks
You get the best out of others when you give the best of yourself.
|
|
|
|