fail to add data into database...
-
hi there, im creating a windows form where it will read data in a file n extract the data into the database.. the data in the files are in this format : 20090301,C4933,ASB02 20090301,C4933,BL689 20090301,C4933,BL707 20090301,C4933,BL714 my app will read the data and will put into the table "portal" - date, runNo, coop.. but when i try, theres no data inside the database. But if i try to display all the data from that file, it can be display. so the problem must be insert the data to the database.. pls check my coding if there's a mistake.. TQ..
Private Sub SEMAK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SEMAK.Click
Dim fileName As String = "X:\\COOPAYPC1\\01032009\\C4933" Dim lineNumber As Integer = 0 Dim sr As StreamReader = New StreamReader(fileName) Dim conn As New SqlClient.SqlConnection("Data Source=MISKPI;User ID= sysadm;Password=sysadm;Initial Catalog=SPGA\_Latihan;Persist Security Info=True") Dim date As String = "" Dim runNo As String = "" Dim coop As String = "" Dim line As String = "" Do line = sr.ReadLine() If line <> Nothing Then Try date= line.Substring(0, 8).Trim() runNo = line.Substring(9, 14).Trim() coop = line.Substring(15).Trim() Catch ex As Exception Console.Write(ex.ToString()) End Try Dim strSQL As String = "INSERT INTO portal (date,runNo, coop) VALUES (@date, @runNo, @coop)" Dim cmd As New System.Data.SqlClient.SqlCommand(strSQL, conn) conn.Open() cmd.Parameters.Add(New SqlClient.SqlParameter("@tarikh", SqlDbType.Char, 8)) cmd.Parameters("@date").Value = date cmd.Parameters.Add(New SqlClient.SqlParameter("@runNo", SqlDbType.Char, 20)) cmd.Parameters("@runNo").Value = runNo cmd.Parameters.Add(New SqlClient.SqlParameter("@coop", SqlDbType.VarChar, 100)) cmd.Parameters("@coop").Value = coop conn.Close() End If Loop Until line Is Nothing sr.Close() End Sub
-
hi there, im creating a windows form where it will read data in a file n extract the data into the database.. the data in the files are in this format : 20090301,C4933,ASB02 20090301,C4933,BL689 20090301,C4933,BL707 20090301,C4933,BL714 my app will read the data and will put into the table "portal" - date, runNo, coop.. but when i try, theres no data inside the database. But if i try to display all the data from that file, it can be display. so the problem must be insert the data to the database.. pls check my coding if there's a mistake.. TQ..
Private Sub SEMAK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SEMAK.Click
Dim fileName As String = "X:\\COOPAYPC1\\01032009\\C4933" Dim lineNumber As Integer = 0 Dim sr As StreamReader = New StreamReader(fileName) Dim conn As New SqlClient.SqlConnection("Data Source=MISKPI;User ID= sysadm;Password=sysadm;Initial Catalog=SPGA\_Latihan;Persist Security Info=True") Dim date As String = "" Dim runNo As String = "" Dim coop As String = "" Dim line As String = "" Do line = sr.ReadLine() If line <> Nothing Then Try date= line.Substring(0, 8).Trim() runNo = line.Substring(9, 14).Trim() coop = line.Substring(15).Trim() Catch ex As Exception Console.Write(ex.ToString()) End Try Dim strSQL As String = "INSERT INTO portal (date,runNo, coop) VALUES (@date, @runNo, @coop)" Dim cmd As New System.Data.SqlClient.SqlCommand(strSQL, conn) conn.Open() cmd.Parameters.Add(New SqlClient.SqlParameter("@tarikh", SqlDbType.Char, 8)) cmd.Parameters("@date").Value = date cmd.Parameters.Add(New SqlClient.SqlParameter("@runNo", SqlDbType.Char, 20)) cmd.Parameters("@runNo").Value = runNo cmd.Parameters.Add(New SqlClient.SqlParameter("@coop", SqlDbType.VarChar, 100)) cmd.Parameters("@coop").Value = coop conn.Close() End If Loop Until line Is Nothing sr.Close() End Sub
well you need to execute your command, don't you?
cmd.Parameters("@coop").Value = coop
cmd.ExecuteNonQuery()
conn.Close()Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
-
well you need to execute your command, don't you?
cmd.Parameters("@coop").Value = coop
cmd.ExecuteNonQuery()
conn.Close()Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
yup, tq for the info.. but still after i did the correction there's an error msg come out.. connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) what does this mean?
-
yup, tq for the info.. but still after i did the correction there's an error msg come out.. connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) what does this mean?
It means you can't connect to your DB, probably because the connection string is wrong, or because your SQL Server does not allow remote connections.
Christian Graus Driven to the arms of OSX by Vista.
-
It means you can't connect to your DB, probably because the connection string is wrong, or because your SQL Server does not allow remote connections.
Christian Graus Driven to the arms of OSX by Vista.
i dont think its bcoz of sql server does not allow remote connection.. iv been copied this coding from my previous web app.. but the one that im doing currently is windows form.. will it cause a problem? bcoz in web app i will put the connection inside the web.config but in this windows form i put in the coding area as i posted b4. if there's no problem using the coding from my web app, that's why im confused.. my web app can connect to the database, can add, update.. :sigh: