Showing posts with label contents. Show all posts
Showing posts with label contents. Show all posts

Friday, March 23, 2012

How can I avoid lots of spaces being added to the end when saving contents of a textbox

Hi

I am using FormView, SQL 2005, VB 2005

When I save the contents of Title and Area entry fields , I have lots of spaces added to the end.

Title and Area are MultiLine Textboxes and database:varchar(100)

I thought I had solved the issue using;

TextBox Title = FormView1.FindControl("TitleTextBox")asTextBox;

TextBox Area = FormView1.FindControl("AreaTextBox")asTextBox;

TitleLenTrim = Title.Text.Trim().ToString();

if (TitleLenTrim.Length > 100)

{

TitleLenTrim = TitleLenTrim.Trim().Substring(0, 99);

}

string AreaLenTrim;

AreaLenTrim = Area.Text.Trim().ToString();

if (AreaLenTrim.Length > 100)

{

AreaLenTrim = AreaLenTrim.Trim().ToString();

}

string insertSQL;

insertSQL ="INSERT INTO Issue(";

insertSQL +="ProjectID, TypeofEntryID, PriorityID ,Title, Area)";

insertSQL +="VALUES ( '";

insertSQL += ProjectID.Text.ToString() +"', '";

insertSQL += EntryTypeID.Text.ToString() +"', '";

insertSQL += PriorityID.Text.ToString() +"', '";

insertSQL += TitleLenTrim.Trim().ToString() +"', '";

insertSQL += AreaLenTrim.Trim().ToString() +"', '";

Is there any other way I could remove spaces?

Thanks in advance.

My guess is that your columns are defined with data typechar instead ofvarchar. SQL Server will pad char columns with spaces.

Also, you should be using Parameters, not concatenating UI-supplied data directly to SQL statements. This is an insecure practice.

|||

Thankstmorton , you were right, I had declared the two columns as char.

Could you please explain more regarding using Parameters, not concatenating UI-supplied data directly to SQL statements?

Thanks in advance

|||

string insertSQL;

insertSQL ="INSERT INTO Issue(";

insertSQL +="ProjectID, TypeofEntryID, PriorityID ,Title, Area)";

insertSQL +="VALUES ( '";

insertSQL += ProjectID.Text.ToString() +"', '";

insertSQL += EntryTypeID.Text.ToString() +"', '";

insertSQL += PriorityID.Text.ToString() +"', '";

insertSQL += TitleLenTrim.Trim().ToString() +"', '";

insertSQL += AreaLenTrim.Trim().ToString() +"', '";

Becomes:

string insertSQL;

insertSQL ="INSERT INTO Issue(ProjectID, TypeofEntryID, PriorityID ,Title, Area) VALUES (@.ProjectID, @.TypeofEntryID, @.PriorityID ,@.Title, @.Area)";

cmdInsert SqlCommand;

cmdInsert=new SqlCommand(insertSQL,conn);

cmdInsert.Parameters.Add("@.ProjectID",SqlDbType.Varchar).Value=ProjectID.Text;

cmdInsert.Parameters.Add("@.EntryTypeID",SqlDbType.Varchar).Value=EntryTypeID.Text;

...

cmdInsert.ExecuteNonQuery;

(Sorry if my C# syntax isn't exact)

|||

Thanks Motley, It works fine until I try to insert a date.

Previous code was

insertSQL +="convert(datetime,'" +DateTime.Now.ToString("dd/MM/yy") +"',3), '";

I tried the code below but the record doesn't save?

Thanks in advance

string date = DateTime.Now.ToString("dd/MM/yy");

insertSQL = "INSERT INTO WorkFlow(IssueID, TaskID, TaskDone, Date ,StaffID) VALUES (@.IDIssue, @.IDTask, @.TaskDone, convert(DateTime,@.Date,3),@.IDStaff)";

cmdInsert.Parameters.Add("IDIssue", SqlDbType.Int).Value = IDIssue.ToString();

cmdInsert.Parameters.Add("IDTask",SqlDbType.Int).Value = IDTask.Text;

cmdInsert.Parameters.Add("TaskDone",SqlDbType.VarChar).Value = TaskDoneTxtbox.Text;

cmdInsert.Parameters.Add("Date",SqlDbType.DateTime).Value = date;

cmdInsert.Parameters.Add("IDStaff",SqlDbType.Int).Value = IDStaff.Text;

Friday, March 9, 2012

How access SqlServer from the Web

Hello:
I apologize my question involves some Web contents, but I don`t know where
expose it.
I have a local Sql Server database running under W2000 server. This machine
have permanent Internet access . Can I connect a Visual Basic program running
in a remote PC machine to the Sql Server Database, directly through the Web ?
I would appreciate any suggestion or reference to technical article.
My best regards.
Roberto
Yes, you can do that.
My recommendation is to use a VPN to the SQL Server rather than directly (if
possible) and lock down the IP address of the client machine on the server
firewall.
Alternatively you can open up the port that SQL Server listens on (incoming)
to the SQL Server machine and open all (outgoing) from the SQL Server
machine. I'd set SQL Server to use a different port other than the default
1433, say 2025 or something (on the server use the Netowkr Configuration
Utility in the SQL program group) - you can get the client to use that port
using the client config utility on the client.
Hope that helps.
Last but not least, get it on SQL Sp4.
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"Roberto Carabajal" <RobertoCarabajal@.discussions.microsoft.com> wrote in
message news:849989E8-B257-4E25-9A2F-2E86CA164C67@.microsoft.com...
> Hello:
> I apologize my question involves some Web contents, but I don`t know
> where
> expose it.
> I have a local Sql Server database running under W2000 server. This
> machine
> have permanent Internet access . Can I connect a Visual Basic program
> running
> in a remote PC machine to the Sql Server Database, directly through the
> Web ?
> I would appreciate any suggestion or reference to technical article.
> My best regards.
> Roberto
|||Tony:
Thanks very much.
Roberto

Wednesday, March 7, 2012

How access SqlServer from the Web

Hello:
I apologize my question involves some Web contents, but I don`t know where
expose it.
I have a local Sql Server database running under W2000 server. This machine
have permanent Internet access . Can I connect a Visual Basic program runnin
g
in a remote PC machine to the Sql Server Database, directly through the Web
?
I would appreciate any suggestion or reference to technical article.
My best regards.
RobertoYes, you can do that.
My recommendation is to use a VPN to the SQL Server rather than directly (if
possible) and lock down the IP address of the client machine on the server
firewall.
Alternatively you can open up the port that SQL Server listens on (incoming)
to the SQL Server machine and open all (outgoing) from the SQL Server
machine. I'd set SQL Server to use a different port other than the default
1433, say 2025 or something (on the server use the Netowkr Configuration
Utility in the SQL program group) - you can get the client to use that port
using the client config utility on the client.
Hope that helps.
Last but not least, get it on SQL Sp4.
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"Roberto Carabajal" <RobertoCarabajal@.discussions.microsoft.com> wrote in
message news:849989E8-B257-4E25-9A2F-2E86CA164C67@.microsoft.com...
> Hello:
> I apologize my question involves some Web contents, but I don`t know
> where
> expose it.
> I have a local Sql Server database running under W2000 server. This
> machine
> have permanent Internet access . Can I connect a Visual Basic program
> running
> in a remote PC machine to the Sql Server Database, directly through the
> Web ?
> I would appreciate any suggestion or reference to technical article.
> My best regards.
> Roberto|||Tony:
Thanks very much.
Roberto

How access SqlServer from the Web

Hello:
I apologize my question involves some Web contents, but I don`t know where
expose it.
I have a local Sql Server database running under W2000 server. This machine
have permanent Internet access . Can I connect a Visual Basic program running
in a remote PC machine to the Sql Server Database, directly through the Web ?
I would appreciate any suggestion or reference to technical article.
My best regards.
RobertoYes, you can do that.
My recommendation is to use a VPN to the SQL Server rather than directly (if
possible) and lock down the IP address of the client machine on the server
firewall.
Alternatively you can open up the port that SQL Server listens on (incoming)
to the SQL Server machine and open all (outgoing) from the SQL Server
machine. I'd set SQL Server to use a different port other than the default
1433, say 2025 or something (on the server use the Netowkr Configuration
Utility in the SQL program group) - you can get the client to use that port
using the client config utility on the client.
Hope that helps.
Last but not least, get it on SQL Sp4.
--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"Roberto Carabajal" <RobertoCarabajal@.discussions.microsoft.com> wrote in
message news:849989E8-B257-4E25-9A2F-2E86CA164C67@.microsoft.com...
> Hello:
> I apologize my question involves some Web contents, but I don`t know
> where
> expose it.
> I have a local Sql Server database running under W2000 server. This
> machine
> have permanent Internet access . Can I connect a Visual Basic program
> running
> in a remote PC machine to the Sql Server Database, directly through the
> Web ?
> I would appreciate any suggestion or reference to technical article.
> My best regards.
> Roberto|||Tony:
Thanks very much.
Roberto

Friday, February 24, 2012

Hotfix contents

Hi,
Does anyone know a source for the contents of the SQL Hotfix which updates SQL2000 to version 8.00.919? I have the hotfix and ran it on a development SQL server but I cannot find a definitive list of the contents. I've been given one article from microsof
t (http://support.microsoft.com/default...b;en-us;837957) but I believe there are more fixes contained therein (I'd hope so at >17mb). I couldn't find anything on knowledge base or technet.
Thanks
DaveK
http://www.sqlporn.co.uk
If you look at the list of files in 837957, I can certainly see that the
updated files add up to at least 17mb uncompressed.
Keep in mind that a certain patch level does not contain just that patch,
but it is cumulative (so that if you thought you needed to apply 918, for
example, you wouldn't have to because it's already there). I keep a list of
the hotfixes at http://www.aspfaq.com/2160 so you can browse through those
other KBs to see what other symptoms were fixed between build 760 and build
919.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"DaveK" <anonymous@.discussions.microsoft.com> wrote in message
news:5BD0BDC4-A4D1-422B-9785-1BF224E167EF@.microsoft.com...
> Hi,
> Does anyone know a source for the contents of the SQL Hotfix which updates
SQL2000 to version 8.00.919? I have the hotfix and ran it on a development
SQL server but I cannot find a definitive list of the contents. I've been
given one article from microsoft
(http://support.microsoft.com/default...b;en-us;837957) but I
believe there are more fixes contained therein (I'd hope so at >17mb). I
couldn't find anything on knowledge base or technet.
> Thanks
> DaveK
> http://www.sqlporn.co.uk

Hotfix contents

Hi
Does anyone know a source for the contents of the SQL Hotfix which updates SQL2000 to version 8.00.919? I have the hotfix and ran it on a development SQL server but I cannot find a definitive list of the contents. I've been given one article from microsoft (http://support.microsoft.com/default.aspx?scid=kb;en-us;837957) but I believe there are more fixes contained therein (I'd hope so at >17mb). I couldn't find anything on knowledge base or technet
Thank
Dave
http://www.sqlporn.co.ukIf you look at the list of files in 837957, I can certainly see that the
updated files add up to at least 17mb uncompressed.
Keep in mind that a certain patch level does not contain just that patch,
but it is cumulative (so that if you thought you needed to apply 918, for
example, you wouldn't have to because it's already there). I keep a list of
the hotfixes at http://www.aspfaq.com/2160 so you can browse through those
other KBs to see what other symptoms were fixed between build 760 and build
919.
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"DaveK" <anonymous@.discussions.microsoft.com> wrote in message
news:5BD0BDC4-A4D1-422B-9785-1BF224E167EF@.microsoft.com...
> Hi,
> Does anyone know a source for the contents of the SQL Hotfix which updates
SQL2000 to version 8.00.919? I have the hotfix and ran it on a development
SQL server but I cannot find a definitive list of the contents. I've been
given one article from microsoft
(http://support.microsoft.com/default.aspx?scid=kb;en-us;837957) but I
believe there are more fixes contained therein (I'd hope so at >17mb). I
couldn't find anything on knowledge base or technet.
> Thanks
> DaveK
> http://www.sqlporn.co.uk

Hotfix contents

Hi,
Does anyone know a source for the contents of the SQL Hotfix which updates S
QL2000 to version 8.00.919? I have the hotfix and ran it on a development SQ
L server but I cannot find a definitive list of the contents. I've been give
n one article from microsof
t (http://support.microsoft.com/defaul...kb;en-us;837957) but I bel
ieve there are more fixes contained therein (I'd hope so at >17mb). I couldn
't find anything on knowledge base or technet.
Thanks
DaveK
http://www.sqlporn.co.ukIf you look at the list of files in 837957, I can certainly see that the
updated files add up to at least 17mb uncompressed.
Keep in mind that a certain patch level does not contain just that patch,
but it is cumulative (so that if you thought you needed to apply 918, for
example, you wouldn't have to because it's already there). I keep a list of
the hotfixes at http://www.aspfaq.com/2160 so you can browse through those
other KBs to see what other symptoms were fixed between build 760 and build
919.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"DaveK" <anonymous@.discussions.microsoft.com> wrote in message
news:5BD0BDC4-A4D1-422B-9785-1BF224E167EF@.microsoft.com...
> Hi,
> Does anyone know a source for the contents of the SQL Hotfix which updates
SQL2000 to version 8.00.919? I have the hotfix and ran it on a development
SQL server but I cannot find a definitive list of the contents. I've been
given one article from microsoft
(http://support.microsoft.com/defaul...kb;en-us;837957) but I
believe there are more fixes contained therein (I'd hope so at >17mb). I
couldn't find anything on knowledge base or technet.
> Thanks
> DaveK
> http://www.sqlporn.co.uk